I am keeping some application meta data in SharedPreferences
. Whenever I uninstall the application and reinstall it, the SharedPreferences
are deleted.
Is there any way to get that to remain, so that if the user does an uninstall and reinstall, they can recover their old data?
SharedPreferences is what Android and iOS apps use to store simple data in an allocated space. This data exists even when the app is shut down and starts up again; we can still retrieve the value as it was.
Android Shared Preferences Overview Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment. getDataDirectory() .
Android's built-in SharedPreferences storage mechanism allows us to store information that persists throughout the entire app.
Shared Preferences allow you to save and retrieve data in the form of key,value pair. In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences.
Since Android 6.0 it has been possible to use:
<application android:allowBackup="true">
By setting it to true your data (sharedprefs and others) will be saved on Google cloud and restored next time the app is installed. You can read more about it here. It should be noted that the default settings is true since 6.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With