I would like to know if the user is using the application for the first time. I am using SharedPreferences
, but I am not sure if I have the right logic.
How can I set my isFirstLaunched
boolean to true when the user first launches, and then immediately set to false after work has been done?
protected void onStart() {
super.onStart();
if(isFirstLaunch()){
populateDefaultQuotes();
//Save the preferences, isFirstLaunch will now be false
SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("isFirstLaunch", false);
editor.commit();
}
setupUI();
checkOrientation();
restoreCache();
}
private void populateDefaultQuotes(){
System.out.println("!!!!!! FIRST TIMER !!!!!!");
}
private boolean isFirstLaunch() {
// Restore preferences
SharedPreferences settings = getSharedPreferences(Constants.PREFS_NAME, 0);
boolean isFirstLaunch = settings.getBoolean("isFirstLaunch", false);
return isFirstLaunch;
}