-1

I know how to make a main activity, in the sense that it is the first screen that opens when the app starts. If I wanted to make sure that the aforementioned activity is the first only when starting the app for the first flight, thus passing the "priority" to another activity, would it be possible? Obviously once the app is uninstalled, the activity the main one goes back to being primary. I hope I have explained, thanks to all

  • Does this answer your question? [How to launch activity only once when app is opened for first time?](https://stackoverflow.com/questions/7238532/how-to-launch-activity-only-once-when-app-is-opened-for-first-time) – VikaS GuttE Jan 29 '21 at 04:30

2 Answers2

2

Sure, the easiest way of doing this is by having one starter activity that decides whether to launch let's say Activity A or Activity B.


The idea is to have an activity StartActivity and set as the main inside the AndroidManifest and inside onCreate we could have something like this:

if (firstTime) {
    startActivity ( new Intent (this, ActivityA.java ) )
} else {
    startActivity ( new Intent (this, ActivityB.java ) )
}
finish()

Once you launch ActivityA you can save a boolean locally that can be used in the variable firstTime the next time StartActivity launches.

You could save the flag value in SharedPreferneces for example.

Khaled
  • 542
  • 1
  • 5
  • 10
0

This first time activity is called SplashActivity. Set SplashActivity launcher in manifest and onCreate of SplashActivity write like this

if(preference.isFirstTime()){
startActivity(Intent(this,MainActivity.class));
finish();
} else {
//your logic in first time launch after install
preference.setFirstTime(false);
}

preference is SharedPrefernces object