Reputation:
I need to start an activity(tutorial) on my first app launch. I figured i could write this in my main but then i realized once the app is closed and start again it would just start the tutorial again.
Boolean first = true;
if(first){
Intent i ......
first = false;
}
so i thought about creating a database or writing a value in a file and saving the Boolean value in that. Is there a easier way for this? thanks in advance
Upvotes: 0
Views: 268
Reputation: 3742
You can use preference for this. You can implement following codes on your onCreate method
SharedPreferences prefs = PreferenceManager.getDefaultPreferences(getApplicationContext());
boolean first = prefs.getBoolean("key_first_launch", true);
if (first)
// show your tutorial
else
// dont show your tutorial
When first tutorial complete, change preference value
SharedPreferences prefs = PreferenceManager.getDefaultPreferences(getApplicationContext());
prefs.edit().putBoolean("key_first_launch", false).commit();
Upvotes: 2
Reputation: 121
You need to save that information, for instance with SharedPreferences, so that it is persistent and read its value when the application is started.
See: http://developer.android.com/reference/android/content/SharedPreferences.html http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html#preferences
Upvotes: 0