Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are SharedPreferences deleted?

Tags:

android

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?

like image 508
Paolo Avatar asked May 15 '13 13:05

Paolo


Video Answer


2 Answers

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.

like image 102
Blackbelt Avatar answered Oct 06 '22 00:10

Blackbelt


  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();
    
like image 25
Wasir Avatar answered Oct 06 '22 01:10

Wasir