Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 964
thomas-hiron Avatar asked Apr 20 '13 10:04

thomas-hiron


1 Answers

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

like image 196
zubair Avatar answered Oct 19 '22 02:10

zubair