Does reinstallation of app delete SQLiteDatabase or SharedPreferences

霸气de小男生 提交于 2019-12-07 08:32:34

问题


I wanted to know whether reinstallation of app deletes SQLiteDatabase or SharedPreferences in Android. Also under what circumstances does it gets deleted. Application will be downloaded from server & installed. If it does get deleted what should we do to take a backup & restore it again?

Please help...


回答1:


No... Database and SharedPreferences will not be deleted if one reinstall the app. They get deleted when some one uninstall it or clear data from settings menu of device...




回答2:


Updating your app (installing newer or the same version) will keep you preferences and all data, unless you do not intentionally delete them in your code.. But if you uninstall the app before installing it again, then yes, all your data will be gone..

In Android Debug Bridge you can specify whether should you install it over the existing installation, or do a clean install with the -r flag (adb install your.apk / adb install -r your.apk)




回答3:


SharedPreferences and SQLiteDatabase are deleted when you

  • uninstall your app.
  • clear data(from settings).

If you want to restore your SharedPreferences and SQLiteDatabase when your app is reinstalled then you should add a BackupAgentHelper to your app. Together with the SharedPreferenceBackupHelper, it backups the SharedPreferences and SQLiteDatabase to the cloud (if the device supports it). When the app is reinstalled the data is restored.

See:

BackupAgentHelper
SharedPreferenceHelper (contains all the code you need to implement it)
general Backup guide

Just let me know if it worked for you. Hope it Helps :) Cheers.



来源:https://stackoverflow.com/questions/21628454/does-reinstallation-of-app-delete-sqlitedatabase-or-sharedpreferences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!