Skip to content

Instantly share code, notes, and snippets.

@ochim
Last active August 10, 2018 10:58
Show Gist options
  • Select an option

  • Save ochim/96039cde2f0090220ed486aa8c2e70d9 to your computer and use it in GitHub Desktop.

Select an option

Save ochim/96039cde2f0090220ed486aa8c2e70d9 to your computer and use it in GitHub Desktop.
[Android] SharedPreferencesで複数キーを消す
private void removeBadKeys() {
    SharedPreferences preferences = getSharedPreferences("hogehoge", 0);
    SharedPreferences.Editor editor = preferences.edit();

    for (String key : preferences.getAll().keySet()) {
        // xxxで始まるキー
        if (key.startsWith("xxx")) {
            editor.remove(key);
        }
    }

    editor.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment