Skip to content

Instantly share code, notes, and snippets.

@anandgaurav10
Last active August 26, 2017 09:56
Show Gist options
  • Save anandgaurav10/a40a909d9410f53322f137cbe9a69303 to your computer and use it in GitHub Desktop.
Save anandgaurav10/a40a909d9410f53322f137cbe9a69303 to your computer and use it in GitHub Desktop.
public class SharedPrefsHelper {
public static final String MY_PREFS = "MY_PREFS";
public static final String EMAIL = "EMAIL";
SharedPreferences mSharedPreferences;
public SharedPrefsHelper(Context context) {
mSharedPreferences = context.getSharedPreferences(MY_PREFS, MODE_PRIVATE);
}
public void clear() {
mSharedPreferences.edit().clear().apply();
}
public void putEmail(String email) {
mSharedPreferences.edit().putString(EMAIL, email).apply();
}
public String getEmail() {
return mSharedPreferences.getString(EMAIL, null);
}
public boolean getLoggedInMode() {
return mSharedPreferences.getBoolean("IS_LOGGED_IN", false);
}
public void setLoggedInMode(boolean loggedIn) {
mSharedPreferences.edit().putBoolean("IS_LOGGED_IN", loggedIn).apply();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment