What Will Happen to the Sharedpreferences on Update an Android App

What will happen to the SharedPreferences on update an Android App?

Cristian here says: your Application data will be remain when user install updates.

But it must be with the same package name to detect as an update of previous App.

EboMike in Warning Android user that app update could lead to losing data from old app version? says:

Quite frankly, losing data due to an upgrade is unacceptable.

Edit:

Normally, the SharedPreferences(as well as other user data) will be kept during the update process, but sometimes, due to some "unknown" problem, the data may get lost, and I guess it is out of your control. So, you can simply believe that the SharedPreferences will be kept(see here).

So,if you want to avoid clearing user's data in upgrading progress,you have to save main data in external storage(this can be a removable storage media,such as an SD card or an internal,non-removable, storage.) and not private for your App.Or at least put away for user to backup data before upgrading .Then in first run of your (upgraded) App,check that is there any backup file in external storage or no.

If you like to know What things must/can happen on upgrading an App?,I did not any good description for this.It is complicated and relative with Android Security,Application signing,copy protection and other topics.I mean that if you change state of your App in any above fields,it causes different result.

For example if you CHANGED COPY PROTECTION FROM ON to OFF OR OFF to ON,your App will be updated but causes all your shared preferences to get lost,file access be impossible and ... .

You although have to be care in about conditions cause your new App being considered as an update for previous App(see Things That Cannot Change).

Also you have to be care in about your code,it may be caused deleting data of your databases(see update app with preloaded SQLite).

But ultimately, if be careful,you can say:

The update process only replaces the apk file(and so what is in it for
example drawables,...) and does not alter databases,sharedpreferences
and any other files that generated in run time(probably in this
case,new App is installed with the UID that is equal to UID of
previous App).

You can see these pages for more details:

Help!? Updating our applicatoin on the market deletes the saved SharedPreferences.

Market copy protection totally breaks file access after updating

Can someone explain the App update process?

Does updating app clear sharedpreferences or remove alarms set by the app?

Normally, the SharedPreferences(as well as other user data) will be kept during the update process, but sometimes, due to some "unknown" problem, the data may get lost, and I guess it is out of your control. So, you can simply believe that the SharedPreferences will be kept.

As for alarms, how did you set these alarms? If you set them in code, it should be 100% ok as long as you set them right in code.

Of course, the best way to test is install your updated app on your device before you push it up to the market. First, you should install your market version of app on your phone, then export your app with your market keystore on your local computer, finally, install the exported version on your phone(the installer should inform you about the update). And you can check if these settings are still there.

While exporting, the most important thing is to make sure you are using the same keystore as you use with the market version of app.

Hope this will help you.

SharedPreferences lost after app update

If you changed a property in the application section of the manifest file, this error will occur and 90% of the time, the shared pref data will be reset. This is what I found from my test installing the signed apk on top of my play store app. Not sure what will happen if the app was installed from the play store as an update, but am pretty sure the data would be lost in that case as well.

EDIT- I republished the application and tested multiple times. This in fact is the issue.

Are shared preferences in Android apps deleted when a user updates the app?

No, the Shared Preferences will remain.

sharedpreferences are cleared on update to new version when using android:allowBackup= false in Manifest?

I don't have enought reputation to post a comment, sorry.

I think your issue is not related to that Manifest attribute, since what it does is to allow the device to include your app info for backups. Little info here.

Could you post how you access to your shared preferences? It's important to access the same preferences, so is it posible that your preferences id is composed with your application version or something similar?
Just guessing, i'll try to be more helpful once you post the code :)

How app shared preference value works after app update from playstore

In your SharedPreferences, when you save a set of key-value pairs that is crucial for operation, such as user settings, and other stuff, always store the version of your application alongside the other values, so you can identify how every value was created. If you then want to read the file, you can detect an older version, and update the key-value pairs to the syntax of the new version.

Obviously you did not specify any version yet in the SharedPreferences, so what you do? You simply introduce a new value for VersionID, and if it is not present in the existing SharedPreferences, you know it was created by the very first version of your application.



Related Topics



Leave a reply



Submit