Skip to content

Instantly share code, notes, and snippets.

@vekexasia
Created April 12, 2012 14:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vekexasia/2367508 to your computer and use it in GitHub Desktop.
Save vekexasia/2367508 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