Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 693
Ben Mc Avatar asked Oct 05 '10 04:10

Ben Mc


People also ask

Can shared preferences be deleted?

SharedPreferences is what Android and iOS apps use to store simple data in an allocated space. This data exists even when the app is shut down and starts up again; we can still retrieve the value as it was. The data stored in SharedPreferences can be edited and deleted.

Does uninstalling app clear shared preferences?

The shared preference is definitely deleted when the application is uninstalled.

Are shared preferences persistent?

Shared preferences is an Android class that allows apps to store key-value pairs of primitive data types. Once saved, information in shared preferences will persist across sessions.

Where shared preferences are stored in Android?

Android Shared Preferences Overview Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment.


2 Answers

No, the Shared Preferences will remain.

like image 78
Cristian Avatar answered Sep 18 '22 07:09

Cristian


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.

like image 32
Lazy Ninja Avatar answered Sep 21 '22 07:09

Lazy Ninja