-
-
Save aug2uag/63a677a9ab1e4d3af21488820c1786e4 to your computer and use it in GitHub Desktop.
Check if the user is opening the app for the first time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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