I am developing an Android app. This app stores preferences (user settings) relative to its functioning, such as preferred image quality, etc. etc.. And purchases too.
My question is: How to store these settings in Android in a way that they remain persistent even if the application is removed.
Specifically purchases. I want the user to be able to purchase an in-app feature, uninstall the app, and if he reinstalls the app and presses a “Restore Purchases” button, the previously purchased feature will be restored.
I am currently using Android’s SharedPreferences to store these settings. I would like some comment on if this will work for my purpose or not.
The short answer for your specific case is to use the “managed by user account” purchase type when you set up in-app billing.
Regarding the general case, your app’s
SharedPreferencesare deleted when your app is uninstalled, so no, this will not work. The only data that is kept around after uninstallation is that stored in a public directory in external storage (usually but not always an SD card). Your app’s private directory on external storage is deleted, along with your databases,SharedPreferences, etc. during uninstallation.It would be in poor form (and not very reliable) to use a public area of external storage to try to save user data for this purpose. The correct solution to the general problem of storing user data across devices or uninstall/reinstall cycles is, as @anoop suggested, to send it to a server.