Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Forked from vekexasia/gist:2367508
Created November 8, 2018 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aug2uag/63a677a9ab1e4d3af21488820c1786e4 to your computer and use it in GitHub Desktop.
Save aug2uag/63a677a9ab1e4d3af21488820c1786e4 to your computer and use it in GitHub Desktop.
Check if the user is opening the app for the first time
private Boolean firstTime = null;
/**
* Checks if the user is opening the app for the first time.
* Note that this method should be placed inside an activity and it can be called multiple times.
* @return boolean
*/
private boolean isFirstTime() {
if (firstTime == null) {
SharedPreferences mPreferences = this.getSharedPreferences("first_time", Context.MODE_PRIVATE);
firstTime = mPreferences.getBoolean("firstTime", true);
if (firstTime) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean("firstTime", false);
editor.commit();
}
}
return firstTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment