Created
December 20, 2015 11:48
-
-
Save hitapia/6552500f08e5c2a005cf to your computer and use it in GitHub Desktop.
Use SharedPreferences - Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void logout(){ | |
| SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
| Editor editor = pref.edit(); | |
| editor.clear(); | |
| editor.commit(); | |
| } | |
| private void storeSomthing(){ | |
| SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
| Editor editor = pref.edit(); | |
| editor.putString("key_name", "string value"); | |
| editor.commit(); | |
| } | |
| private String getSomthing(String key){ | |
| SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
| Editor editor = pref.edit(); | |
| return editor.getString(key, "string value"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment