Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

cordova - How permanent is local storage on Android and iOS?

When my app stores data locally on a phone, how permanent is that storage? I'll elaborate the exact situation:

I'm building an app with jQueryMobile and Phonegap. It's essentially a browser app, but using Phonegap lets me package it and sell it in the app stores, among other advantages.

Phonegap offers two ways of storage, both of which functions harmonize native functions of iOs, Android, Blackberry and some other OSs: localStorage (which is primitive key-value pairs), and a Web SQL database. Both localStorage and web SQL are forms of storage that belong to the browser. Having said that, I can't find out how long the data will stay stored, under what circumstances it will be deleted, under what circumstances it may not be available, etc.

For example, if the app stores data with localStorage or web SQL, and the user switches to a different standard browser on their Android, will the app be opened with the new browser and does that mean that the stored data is unavailable?

If the user doesn't use the app for a year (which in my case is a realistic and not necessarily a bad scenario), will the data have expired like a cookie, or maybe been pushed out of the browser's storage by a deluge of data from other apps?

Or will the data be destroyed even earlier, such as when: - user visits another site in the browser - browser is manually closed - browser process is killed or dies - etc

Or are localStorage and web SQL the kind of storage that you only delete when (in Android) you go to Settings > Apps and actively remove the user data associated with the app?

Thanks for any insights. There's nothing informative out there on ol' WWW.

What happens in the case of app update. The local and web storage will get deleted or will it stay?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Let me answer step by step

if the app stores data with localStorage or web SQL, and the user switches to a different standard browser on their Android, will the app be opened with the new browser and does that mean that the stored data is unavailable?

The data is saved in the 'cache'(its not exactly the cache) of the browser, so if you change the browser, or set the settings so that the default browser is removed or changed, the data will go.

If the user doesn't use the app for a year (which in my case is a realistic and not necessarily a bad scenario), will the data have expired like a cookie, or maybe been pushed out of the browser's storage by a deluge of data from other apps?

No, the data will stay there no matter for how long it is not used. So even if you clear the browser cache, it will still be there.

Or will the data be destroyed even earlier, such as when: - user visits another site in the browser - browser is manually closed - browser process is killed or dies - etc

No, the data stays all right. :-)

Or are localStorage and web SQL the kind of storage that you only delete when (in Android) you go to Settings > Apps and actively remove the user data associated with the app?

Yes, the data only goes if you either manually delete it from your app or you uninstall your app. It will stay in all other cases.

EDIT: In the case of iOS, the OS will remove the data in the local storage when there is a shortage of memory in the device.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...