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
SharedPreferences prefs = Context.getSharedPreferences("FileName", Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.clear();
editor.commit();
Just call editor.clear();
to reset it.
Just add editor.clear();
It will reset the settings.
Ensure you have default values set for each pref in the XML file. Eg:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.