Skip to content Skip to sidebar Skip to footer

Android Shared Preference Still Visible After Deleting File

I am trying an application where I am using Shared Preference. When I delete the preference file from data/data/com.your.package.name/shared_prefs/mySharedPref.xml manually using

Solution 1:

I think this code must work

publicstaticvoidclearAllPreference(Context context){
        SharedPreferencesprefs= context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
        SharedPreferences.Editoreditor= prefs.edit();
        editor.clear();
        editor.commit();
    }

Solution 2:

To remove specific values: SharedPreferences.Editor.remove() followed by a commit()

To remove them all SharedPreferences.Editor.clear() followed by a commit()

You use remove() to remove specific preferences, you use clear() to remove them all.

Checkout official documentation on SharedPreferences.Editor.

Post a Comment for "Android Shared Preference Still Visible After Deleting File"