Delete All Sharedpreferences from Android App

Asked

Viewed 1,603 times

-1

I am in the middle of a development of an application on ANDROID, which contains many Activity and for each Activity has some checkbox and I am using Sharedpreferences to save what was selected if the user wants to go back on screen. But I need to delete all Sharedpreferences when starting the application. How can I do this ?

2 answers

2


Do so:

SharedPreferences.Editor prefsEditor = getSharedPreferences(arquivo, 0).edit();
prefsEditor.clear();
prefsEditor.commit();

This will remove all stored values.

  • In getSharedPreferences(), this obliges me to pass all String. It would have some way, and all Sharedpreferences are under the same name.

0

I did it this way:

public void deletarSharedPreferences()
    {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.