tags:

views:

238

answers:

2

Long story short, I have a LaunchActivity which is always called by LAUNCHER (i.e. the home screen). It then starts LoginActivity and then closes itself.

This is the flow:

  1. User launches app
  2. LaunchActivity starts, starts LoginActivity and then calls finish() on itself (At this point LoginActivity is the only Activity on the stack)
  3. User press "Home" button, stopping LoginActivity
  4. User launches the app again

When the app is launched for the 2nd time, two things can happen:

  1. LaunchActivity starts, finishes itself and then STARTS LoginActivity
  2. LaunchActivity starts, finishes itself and then CREATES LoginActivity, so there are now two LoginActivitys on the stack.

(2) seems to happen when I restart Eclipse and the simulator (yeah I know, black magic).

Some extra info: I'm not using any start flags and my manifest doesn't have any launchModes defined.

A: 

I imagine it has to do with whether or not the LoginActivity needed to be killed while it was in the background. As the activity lifecycle explains, an activity that is stopped (not visible) can be killed if the system needs to resources.

Mayra
+3  A: 

I think you want to set android:launchMode="singleTask" There's a basic explanation here:

http://groups.google.com/group/android-developers/browse_thread/thread/e29bd82a7fec43c6/44835d74b0af3f5f?lnk=gst&q=ellipsoidmobile#44835d74b0af3f5f

From the link "If your activity is launched from another application, without using single task, but you want this to cause your current app to come to the foreground instead of a new instance of that activity started in the other app's task. An example of an app that does this is the browser. "

From reading your question, this looks like what you want. Set launchMode="singleTask" on your LoginActivity and when your LaunchActivity starts the LoginActivity it should restart the existing one instead of creating a second instance.

haseman