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

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

If I store some user settings and information in shared preferences in my android apps, and then I update the app in the Market, will those settings be erased when the app updates?

How to&Answers:

No, the Shared Preferences will remain.

Answer:

To make the answer simple: NO in normal circumstances.

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

But following this thread it seems that there are cases when data could be lost. Like changing Copy PROTECTION FROM ON to OFF OR OFF to ON.
Quoting the answer:

It turns out when we posted the update copy protection was turned off,
but for our initial release it was turned on. Which caused all our
shared preferences to get lost, we could no longer create private data
files, and the game started randomly crashing.