Android- How do I know if an application is launching for the first time?

How do I know if an application is launching for the first time?

If you are responding, add the full code because I read several answers and I did not understand them.

Thanks.

+4
source share
4 answers

Use sharedPreferences for persistent data storage. When the application first starts, just save the boolean value in the general settings. Then check every time.

 SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE); SharedPreferences.Editor prefEditor = sharedPref.edit(); prefEditor.putString("isLauncedTime",true); prefEditor.commit(); 
+11
source

Each application gets a way to save settings or parameters, so you can use it to see if the application was previously launched.

 SharedPreferences runCheck = PreferenceManager.getSharedPreferences("hasRunBefore", 0); //load the preferences Boolean hasRun = runCheck.getBoolean("hasRun", false); //see if it run before, default no if (!hasRun) { SharedPreferences settings = getSharedPreferences("hasRunBefore", 0); SharedPreferences.Editor edit = settings.edit(); edit.putBoolean("hasRun", true); //set to has run edit.commit(); //apply //code for if this is the first time the app has run } else { //code if the app HAS run before } 
+17
source

You can refer to http://developer.android.com/guide/topics/data/data-storage.html#pref .

You can load a boolean the first time you run the application for general settings, and then check if it really runs on subsequent launches, so you know that the program has already been run once.

+5
source

I don't know if this is the best solution, but ...

I tried to save a simple boolean value in the Android file system and when starting the Android application, checking if this boolean exists and what its value is.

Again, not sure if this is the right way to do this, this is just my own way of getting around this.

0
source

Source: https://habr.com/ru/post/1387757/


All Articles