I want to clear all but one SharedPreference. If I've saved 10+, is there a better way then removing each individually? This gets a bit redundant:
preferences.edit().remove("1").commit();
preferences.edit().remove("2").commit();
preferences.edit().remove("3").commit();
...
preferences.edit().remove("15").commit();
You could also get the value you want to keep, clear()
, and re-add it before commiting.
you can loop through all the keys
Map<String,?> prefs = pref.getAll();
for(Map.Entry<String,?> prefToReset : prefs.entrySet()){
edit.remove(prefToReset.getKey()).commit();
}
then skip over the key/s you dont want to remove
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With