Removing keys

suggest change
private 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents