Reputation: 93
I need to make a greeting message when the user installed and run apps for the first time. What's the simple way to get the app is running for the first time?
Upvotes: 0
Views: 130
Reputation: 23279
Use SharedPreferences
to store a flag of whether you need to show the message or not.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean showMsg = prefs.getBoolean("show_msg", true);
if (showMsg) {
// show the message
// then save the flag
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("show_msg", false);
editor.commit();
}
Put this in onCreate()
or similar.
Next time the snippet is run the value will be false so the message will not be shown.
Upvotes: 1