Paolo
Paolo

Reputation: 2472

When are SharedPreferences deleted?

SharedPreferences class allows to save application data in simple type (boolean, String, etc.) formats.

Normally they are not removed and they are supposed to persist, but are they removed in case such as when application is updated/removed or application cache is cleared?

Upvotes: 11

Views: 9081

Answers (4)

User Rebo
User Rebo

Reputation: 4590

It also happens, if you force install an old app version (lower build number) on top of the current one.

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157437

when you do clear data from the device applications manager or when you uninstall your application, the SharedPreference's file is deleted.

SharePreferences are stored inside

/data/data/packagename/shared_prefs/prefsname.xml

unless you have the android:allowBackup="true" in your manifest. In that case they might be restored.

Upvotes: 20

Wasir
Wasir

Reputation: 185

  1. Sharedpreferences will clear when you clear application data from Application manager by force.

  2. If you want to clear your application Sharepreference data, then you can use:

    PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
    

Upvotes: 4

PankajAndroid
PankajAndroid

Reputation: 2707

Go to Setting->Application setting->Application->Clear data and force data will clear all the data of application (sqlitedatabase and shared preferences) are removed.

Upvotes: 3

Related Questions