Larry The Blackbird
Larry The Blackbird

Reputation: 89

Reset Settings Preferences

Does anyone know how I could reset all of the settings in my app? Imagine I have some checkboxes and list preferences. How could I reset everything to how it was just after the app was installed - the checkbox preferences are checked/unchecked, the list preferences reset to the default value)?

Thanks

Upvotes: 1

Views: 2026

Answers (3)

usajnf
usajnf

Reputation: 522

Ensure you have default values set for each pref in the XML file. E.g.:

android:defaultValue="3600000"/>

Then you can do this in the code:

// Log.d(TAG, "Setting default preference values.");
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

Upvotes: 0

Itiel Maimon
Itiel Maimon

Reputation: 854

Just add editor.clear(); It will reset the settings.

Upvotes: 1

DAVIDBALAS1
DAVIDBALAS1

Reputation: 484

SharedPreferences prefs = Context.getSharedPreferences("FileName", Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.clear();
editor.commit();

Just call editor.clear(); to reset it.

Upvotes: 3

Related Questions