Skip to content

Instantly share code, notes, and snippets.

@jaisonfdo
Last active February 10, 2020 12:00
Show Gist options
  • Save jaisonfdo/dae622b17e42843cfb99ef3dd8a518e0 to your computer and use it in GitHub Desktop.
Save jaisonfdo/dae622b17e42843cfb99ef3dd8a518e0 to your computer and use it in GitHub Desktop.
Shared preference API explanation sample code snippet
getSharedPreferences(FILE_NAME, MODE);
SharedPreferences appSharedPrefs;
appSharedPrefs = context.
getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor;
prefsEditor = appSharedPrefs.edit();
prefsEditor.putString(keyName, String.valueOf(value));
prefsEditor.putBoolean(keyName, (Boolean) value);
prefsEditor.apply();
value = appSharedPrefs.getString(keyName, "");
value = appSharedPrefs.getString(keyName, defaultValue);
prefsEditor.remove(keyName).apply();
prefsEditor.clear().commit();
data/data/<APP_ID>/shared_prefs/<FILE_NAME>.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment