Android: How to create a function that will be executed only once?

How to create a function that will be run only once, during the first installation? I am trying to create information that is displayed once.

early.

+4
source share
1 answer

You can use the flag in general settings .

Then at each start you check this flag. If it is not installed, you display your first message, and then set the flag.

For instance:

@Override protected void onCreate(Bundle state){ super.onCreate(state); . . . SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); boolean firstStart = settings.getBoolean("firstStart", true); if(firstStart) { //display your Message here SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("firstStart", false); editor.commit(); } } 
+12
source

All Articles