1
votes

There is an application with 2 activities: Splash screen and main screen. After installing application it shows splash, then finishes Splash activity and starts main activity. Then i test 3 scenarios:

  1. App is launched, second activity showed on screen. I kill app process by DDMS, launch app again — everything is right — i see splash again, then second activity

  2. App is launched, second activity showed on screen. I press back key, then kill process, launch application again — everything all right too, it launch splash first

  3. App is launched, second activity showed on screen. I press home key, then kill process, launch application again — and there is surprise — application starts on second activity, escaping splash.

What`s wrong?

There is some others question like this one, but i still got no answer.

Can anybody explain this behavior?

2
you should link to the relevant questions as this may helpMoog

2 Answers

2
votes

Splash screens aren't a real good idea anyway since it gives the user the feeling that the application is an add-on and breaks slightly the whole system life cycle.

But if you really want to have a splash screen on the launch Activity, there are two options. One is to have two views inside a root RelativeLayout. One with the splash screen inside an ImageView and another layout with the actual content of the activity. Then, hide the ImageView with your favorite animation.

Alternatively, you can use a fragment instead of the content layout and load the Activity instances (What used to be done with ActivityGroup).


Update:

Ok, I forgot to mention why is that happening in your app. In any Android application we have a loosely bound set of activities and (usually) when we launch a new Activity it gets added to an Activity stack (to manage the back behavior). I say usually because you can change that behavior if required (launchMode).

When you press the back button the stack is emptied and the activity terminated. On the other hand, when pressing the home button, the stack is saved and restored when relaunching.

The Android life cycle can be a bit of a headache sometimes, but once you understand it is really well thought through.

here is some further reading: Activity and Task Design Guidelines

0
votes

Application always starts from where you were before.... Lets say you have 5 seconds. You open the app for 4 seconds with the splash screen. You close the app. You open it. There is only 1 second left for the splash screen