thomas-hiron
thomas-hiron

Reputation: 948

LocalStorage not persistent with Phonegap

I'd like to keep data on user's mobile with localStorage. My app is build with phonegap.

function check_connection()
{
    var id = window.localStorage.getItem("id");
    if(id != null)
        // some code
    console.log(id);
}

When I do this code after window.localStorage.setItem("id", "value");, I get "value", but if I exit the application and run it again, I get "null".

document.addEventListener("deviceready", main, true);
function main()
{
    check_connection();
}

The exit seems to clear the localStorage object.

Any idea ?

EDIT : The data is persistent when I quit the app by pressing back button, but when I kill the app from recent apps, the data is cleared. What is the problem ?

Upvotes: 10

Views: 6450

Answers (1)

zubair
zubair

Reputation: 185

are you calling somewhere window.localStorage.clear();?

Upvotes: 1

Related Questions