Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In android is there any way to preserve SharedPreferences after an uninstall

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?

like image 464
Victor Grazi Avatar asked Mar 22 '12 01:03

Victor Grazi


People also ask

Can data in SharedPreferences persist after rebooting?

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.

Where are Android SharedPreferences stored?

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() .

Are SharedPreferences persistent?

Android's built-in SharedPreferences storage mechanism allows us to store information that persists throughout the entire app.

How save and retrieve data using SharedPreferences in Android?

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.


1 Answers

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.

like image 105
Warpzit Avatar answered Oct 10 '22 21:10

Warpzit