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

Victor Grazi picture Victor Grazi · Mar 22, 2012 · Viewed 15.8k times · Source

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?

Answer

Warpzit picture Warpzit · Apr 7, 2016

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.