0

I'm creating an Android app that uses Preferences. One of the types of preferences that I'm using is the EditTextPreference that brings up a default Android dialog modal with a text input and OK and Cancel buttons.

I want to give users the option to clear out ALL stored values from the list preferences and I cannot find a way to clear out the value for this EditTextPreference.

The way I can test it for now is by clearing it on the OnCreate method override but in the future, I'm going to have it clear it out when a user clicks a button.

So, question: How do you clear out the stored value for an EditTextPreference in Android? I want to remove whatever value that is being saved.

Every time I launch the app (even after clearing it from Memory), whatever last value I entered comes back.

Mario A Guzman
  • 3,483
  • 4
  • 27
  • 36
  • I understand that, and for the most part, I do want the information to be saved so that it is in place next time the user uses the app. But what if I want to clear out all the values to bring the app as new? I want this stored value to be wiped out. – Mario A Guzman Jul 19 '14 at 20:48

1 Answers1

1

Just call clear on the SharedPreference Editor. If you want easy management of SharedPreference's without writing any boilerplate code I have nice little library EasyPrefs

private void clearPrefs() {
    SharedPreferences settings = getSharedPreferences(YOUR_PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.clear().apply();
}
Aegis
  • 5,761
  • 2
  • 33
  • 42
  • This seemed to have worked just fine! If I quit the app from the phone, the value seems to come back, but if I re-run it from the project, it seems to clear out the values as I want it to. I can maybe continue working from this point on, but if you have other suggestions, I'd love to hear them. Thanks for this! It's a huge move forward for me! – Mario A Guzman Jul 19 '14 at 21:03
  • wish it worked for me. I have tried every solution on this site for the last 5 hrs and I cannot get it to work. How can Android make something that should be so simple SOOO difficult? – Brian Reinhold Jan 14 '17 at 01:44