blackHawk
blackHawk

Reputation: 6307

How to always launch application from splash screen then last left activity

In my application I have several activities, If I'm leaving application in the middle of the application next time when application relaunches it starts with where I left I want my application to relaunch from splash screen and then it should move to the activity where i left, how can I do that

Upvotes: 7

Views: 1191

Answers (1)

Vadims Savjolovs
Vadims Savjolovs

Reputation: 2668

What exactly you mean be leaving the app?

Scenario 1: If user completely removed the app from the recent apps (it was terminated) next time user will open the app LAUNCHER (see AndroidManifest.xml) will be launched. So you should make your SplashActivity a LAUNCHER activity.

Scenario 2: In user minimised the app onPause and onStop and maybe onDestroy lifecycle methods on the current activity will be called. After user will restore the app from the recents (if the activity was destroyed then first onCreate method will be called) then onStart and onResume lifecycle methods will be called. See more on lifecycle methods in the docs.

Showing the splash screen each time user minimises and restores the app from recents not a particularly good idea, so I would recommended to stick with "Scenario 1" and show splash screen only once - when user launches the app. But if for some reason you want to show splash screen each time after user restores the app you can check this tutorial. It might be a bit tricky in Android as you can't show it just onResume or onStart as those methods will be called not only when you restore the app from the recents but also when you start this activity.

Upvotes: 2

Related Questions