What happens to SharedPreferences when updating an Android app?

I saved the user settings in SharedPreferences in my application. What happens to SharedPreferences when updating an application through the Google Play Store to a new version of the application?

Will SharedPrefernces remain after the upgrade, or will they be deleted?

So far, I have not found an answer on the Internet or in Stackoverflow (can I search for incorrect keywords?).

Can you point me to some links that describe this process?

Edit: Meanwhile, I found another answer: SharedPreferences behavior when updating / deleting

Edit 2: Since I first asked this question, I recently found out that with Android 6.0 (API 23) you can also use the automatic backup function to protect your general settings, as described by Google here . Just add allowBackup="true" to your AndroidManifest.xml file.

+56
android sharedpreferences updates
Sep 28
source share
3 answers

Cristian says here : your application data will remain when the user installs updates.

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

EboMike's Android User Warning that updating an application could result in data loss from an old version of the application? He speaks:

Quite frankly, data loss due to an update is unacceptable.

Edit

Usually , SharedPreferences (as well as other user data) will be saved during the update process, but sometimes due to some "unknown" problem, the data may be lost, and I think this is not under your control. So, you can just believe that SharedPreferences will be saved ( see here ).

So, if you want to avoid cleaning user data during the upgrade, you need to save the main data in external storage (it can be removable storage media such as an SD card or internal non-removable storage.), And not privately for your App.Or, by at least remove data backups for the user before updating. Then, when you first launch your (updated) application, check if there is a backup file in the external storage or not.

If you like to know what you need / can happen when updating the application? , for this there was no good description. This is complex and relative with Android Security , Application signing , copy protection and other topics. I mean, if you change the state of your application in any of the above fields, it will lead to a different result.
For example, if you CHANGED COPY PROTECTION FROM ON to OFF OR OFF to ON , your application will be updated, but all your general settings will be lost, access to files will be impossible and ....
You, although you must take care of the conditions, invoke the new application being considered as an update for the previous application (see Things That Cannot Change ).

You should also take care of your code, this may be due to the deletion of your database data (see updating the application with SQLite preinstalled ).

But ultimately, if you be careful, you can say:

The update process replaces only the apk file (and therefore, what is in it for drawables examples, ...) and does not change the databases, sharedpreferences and any other files created at run time (perhaps in this case, a new application is installed with UID equal to the UID of the previous application).

You can see these pages for more details:

Reference!? Updating our application on the market deletes saved SharedPreferences.
Copy protection in the market completely interrupts access to files after updating
Can someone explain the process of updating the application?

+52
Sep 28 '12 at 10:10
source share

I think that when I updated my application the last time through Google Play, sharedPreferences was not affected.
I used them to automatically log in, and after updating he did it.
It was a month ago, my memory may become fuzzy, so it's better to hear the opinions of other people.

+4
Sep 28 '12 at 10:09
source share

After debugging for more than 4 hours, I found out that I saved the model as a string, serializing it. A serializable class has a unique identifier named serialVersionUID , which is set by default at run time, and id is calculated by the name of the class, interfaces, and variable names. I found out that I changed the model class, added the variable, and then updated the application. Since the class is now changed, therefore, a new serialVersionUID was set, and therefore, when updating, it was not able to deserialize the string and create a model and provided a java.io.InvalidClassException

Set serialVersionUID explicitly to avoid this problem.

 static final long serialVersionUID = 42L; 
+4
Aug 20 '16 at 8:02
source share



All Articles