tags:

views:

37

answers:

1

Hi all. I'm experiencing kind of strange behavior of my application after hard Home button is pressed. When you press Home, everything is OK - my app goes to the background, showing Home screen. But if you try to choose my app in the main menu or in the list of last tasks it behaves like it was not started before and does not show the last activity you were on - it just starts from scratch, namely, shows the splash screen and starts next corresponding activities. Moreover, old activities of this app remain on the activities stack, and previous instance of the app is not terminated - so if you press Back for a few times you'll just run into those activities which were undoubtedly started during the previous session of work with my app. Splash screen activity is filtered by "android.intent.action.MAIN" filter and "android.intent.category.LAUNCHER" category. The strange thing is that all of that happens despite the fact that I do not intercept any Back key hits, or override any onPause or onResume methods. What's happening contradicts with my understanding of Android app lifecycle - I was sure that when you hit Home an app just goes to the background, and when you choose it in the menu later - it just unwinds and does not start anew. (Of course, unless stuff like that is stated in the app manifest or corresponding methods are overridden or something else). I also checked it for some other lifecycle events - such as changing orientation or flipping hard keyboard out - and none of those led to such strange results. It appears that the problem occurs when you try to start the app from main menu or menu of last applications. I hope you will be able to help me. Any advice on what to pay attention to or where to search for solution would be really great.

Regards, Alex

A: 

You need to set android:launchMode="singleTask" in your LAUNCHER activity in your manifest file.

For more info on the launchMode attribute see here

Note that:

The default mode is "standard".

and:

Every time there's new intent for a "standard" activity, a new instance of the class is created to respond to that intent.

mbaird
Thank you very much for your reply.Unfortunately, changing launchMode did not help. It influences whether onCreate or onResume of my splash screen activity is called first, lol :) However, the true problem is that when you try to open the app after minimizing it the system does not just take last activity from the top of the stack, but instead refers to LAUNCHER activity and tries to re-create, or resume it - does not matter. I'm just puzzled by such strange choice of activity to show to user on app reopen - e.g. native Messaging app always returns you to where you were, not to the start.
Alex P
That doesn't make much sense regarding your splash activity. Is your splash activity the one configured as your LAUNCHER activity in your manifest?
mbaird
You might also want to look here: http://stackoverflow.com/questions/2061143/android-keep-tasks-activity-stack-after-restart-from-home/2061447
mbaird