0

I am developing an HTML5 bases webapp and plan to make post it as native app using phonegap or sencha.

I need something to store my local app data ~2MB( can be name value pair), but storage needs to be persistant and should not be deleted on phone restart or resetting to factory defaults.

what is the scope of SharedPreferences and localstorage in andriod, can a user clear them or what is their lifetime and under what conditions are they cleared.

My other question would be about sqlite, does andriod backup mgr takes a backup of that and restores it if user restores the phone and can sqlite db be cleared by user

Jay Piscean
  • 47
  • 1
  • 7

1 Answers1

0

SharedPreferences and localStorage are accessible only from the originating application. localStorage usually has a limit of 5MB, but not on all phones, some will allow for more. Also, localStorage is available from API level 7 only.

Both SharedPreferences and localStorage are cleared, when user goes to the Application settings and clears the data manually.

If your API level is 8 or higher, you can use the external files directory, which too is exclusive to the application. The only way for the user to clean the data in this directory is by uninstalling the application. You can get the path to it like this:

context.getExternalFilesDir(null).getAbsolutePath();

If your API level is < 8, then you can still use the standard sdCard location for storage, but the files will be there after the user has uninstalled the application.

So your best bet is to store the SQLite database on the external files directory, or sdCard, if the API minimum level is < 8.

Demonick
  • 2,116
  • 3
  • 30
  • 40
  • thanks, is the SQLite db backed up and restored by andriod backup mgr? Since i am developing web app so i cant use API's directly – Jay Piscean May 22 '12 at 03:25
  • I guess you have to do it manually, check this question: http://stackoverflow.com/questions/2170031/backup-and-restore-sqlite-database-to-sdcard – Demonick May 22 '12 at 05:29