Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing the setup screen only on first launch in android

I am making an android application but i can't figure out how i can make the setup screen show up only the first time. This is how the application is going to work: User launches the application after installation and is being shown the welcome/setup screen. And once the user is done with the setup, the setup screens will never appear again unless the user reinstalls the application.

How can i make this happen??? Please help and thanks SO much in advance!

like image 995
MySoftware Avatar asked Dec 13 '22 06:12

MySoftware


1 Answers

Use SharedPreferences to test whether its the first start or not.

Note: The below code was not tested.

In your onCreate (or whereever you want to do things depending on first start or not), add

// here goes standard code 

SharedPreferences pref = getSharedPreferences("mypref", MODE_PRIVATE);

if(pref.getBoolean("firststart", true)){
   // update sharedpreference - another start wont be the first
   SharedPreferences.Editor editor = pref.edit();
   editor.putBoolean("firststart", false);
   editor.commit(); // apply changes

   // first start, show your dialog | first-run code goes here
}

// here goes standard code
like image 102
poitroae Avatar answered Dec 14 '22 20:12

poitroae