Skip to content

Instantly share code, notes, and snippets.

@shikto1
Last active July 2, 2018 10:00
Show Gist options
  • Save shikto1/caebf623b083a78216da4c178e3f9380 to your computer and use it in GitHub Desktop.
Save shikto1/caebf623b083a78216da4c178e3f9380 to your computer and use it in GitHub Desktop.
public class SessionManager {
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
private final String MY_PREF = "my_preferences";
public SessionManager(Context context) {
sharedPreferences = context.getSharedPreferences(MY_PREF, MODE_PRIVATE);
}
public void firstTimeAsking(String permission, boolean isFirstTime) {
doEdit();
editor.putBoolean(permission, isFirstTime);
doCommit();
}
public boolean isFirstTimeAsking(String permission) {
return sharedPreferences.getBoolean(permission, true);
}
private void doEdit() {
if (editor == null) {
editor = sharedPreferences.edit();
}
}
private void doCommit() {
if (editor != null) {
editor.commit();
editor = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment