Clear data from shared privilege in android application

Since I am new to Android development.

After the user clicks the exit button from my application, I want to delete all the information that I saved in the general privilege.

I used this one editor.clear(), but it will not work,

I want to delete this XML file, which is created in conjunction with pref after the user clicks the logout button. I want to delete this file at runtime?

thnx for any help ....

+3
source share
2 answers

You need to make changes:

editor.clear();
editor.commit();

Get this help

+11
source

Try editor.clear();and theneditor.commit();


Edit:

Here is one example that I used:

Preference clearPref = (Preference) findPreference("clearAll");
    clearPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

    public boolean onPreferenceClick(Preference preference) {
        SharedPreferences settings =  PreferenceManager.getDefaultSharedPreferences(getBaseContext());                          
        SharedPreferences.Editor editor = settings.edit();
        editor.clear();
        editor.commit();                
        Toast.makeText(getBaseContext(), "All data cleared!", Toast.LENGTH_SHORT).show();

        return true;
    }

});
+4
source

Source: https://habr.com/ru/post/1795488/


All Articles