Created
October 15, 2018 14:21
-
-
Save fethica/1dc8feefc9de5e36fe91365cb8988789 to your computer and use it in GitHub Desktop.
This file contains 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
// Source: https://stackoverflow.com/questions/17753800/android-default-values-for-shared-preferences | |
public class Preferences { | |
public static final String MY_PREF = "MyPreferences"; | |
private SharedPreferences sharedPreferences; | |
private Editor editor; | |
public Preferences(Context context) { | |
this.sharedPreferences = context.getSharedPreferences(MY_PREF, 0); | |
this.editor = this.sharedPreferences.edit(); | |
} | |
public void set(String key, String value) { | |
this.editor.putString(key, value); | |
this.editor.commit(); | |
} | |
public String get(String key) { | |
return this.sharedPreferences.getString(key, null); | |
} | |
public void clear(String key) { | |
this.editor.remove(key); | |
this.editor.commit(); | |
} | |
public void clear() { | |
this.editor.clear(); | |
this.editor.commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment