Removing keys
suggest changeprivate static final String MY_PREF = "MyPref";
// ...
SharedPreferences prefs = ...;
// ...
SharedPreferences.Editor editor = prefs.edit();
editor.putString(MY_PREF, "value");
editor.remove(MY_PREF);
editor.apply();
After the apply(), MY_PREF is absent. putString and remove for the same key share one pending entry, so the later remove replaces the earlier put. The Editor stores the changes and applies them together; for each key, the last edit is the one that is written.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents