Skip to content

Instantly share code, notes, and snippets.

@JChudasama
Created August 11, 2015 16:23
Show Gist options
  • Save JChudasama/d1f4603b1747cb0341b9 to your computer and use it in GitHub Desktop.
Save JChudasama/d1f4603b1747cb0341b9 to your computer and use it in GitHub Desktop.
public class AppPreferences {
private SharedPreferences preferences;
private SharedPreferences.Editor editor;
private static AppPreferences instancePreferences;
/**
* Preferences' key to be stored at one place
*/
public class PREF_KEYS {
}
public AppPreferences(Context context) {
instancePreferences = this;
preferences = context.getSharedPreferences("AppPreferences.json", Context.MODE_PRIVATE);
editor = preferences.edit();
}
public static AppPreferences getInstance() {
return instancePreferences;
}
public boolean storeString(String key, String value) {
editor.putString(key, value);
return editor.commit();
}
public String getString(String key) {
return preferences.getString(key, null);
}
public boolean storeBoolean(String key, boolean value) {
editor.putBoolean(key, value);
return editor.commit();
}
public boolean getBoolean(String key) {
return preferences.getBoolean(key, false);
}
public boolean storeInt(String key, int value) {
editor.putInt(key, value);
return editor.commit();
}
public int getInt(String key) {
return preferences.getInt(key, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment