2013-04-20 53 views
10

我想用localStorage將用戶的手機數據保存下來。我的應用程序是用phonegap構建的。LocalStorage與Phonegap不一致

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

當我做window.localStorage.setItem("id", "value");此代碼後,我得到的「價值」,但如果我退出應用程序,然後再次運行它,我得到「空」。

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

退出似乎清除localStorage對象。

有什麼想法?

編輯︰數據是持久性的,當我退出應用程序通過按回來的按鈕,但是當我從最近的應用程序殺死應用程序,數據被清除。問題是什麼 ?

+0

http://stackoverflow.com/questions/10881059/localstorage-cleared-on-app-restart-with-cordova-1-7-and-ios-5-1-1試試這個 – zubair 2013-04-20 10:51:39

+0

它也不是太堅持: s – 2013-04-20 10:54:29

+0

這個問題有一個工作答案,不需要使用數據庫http://stackoverflow.com/questions/16240613/localstorage-store-not-persisting-on-android-phone-when-app-stops-using- sencha-t – George 2013-09-11 21:28:24

回答

1

你在打電話window.localStorage.clear();?

+0

是的,我試圖刪除這些行,但它不工作。看看我的編輯 – 2013-04-20 11:05:33

+0

當應用程序通過任務管理器被殺死時,javascript進程隨後被終止。當JavaScript被殺死時,它不會觸發您可以採取行動的事件。 – zubair 2013-04-20 11:11:02

+0

那麼有沒有解決方案?或者我不能使用localstorage? – 2013-04-20 11:12:16