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:
- User launches app
- LaunchActivity starts, starts
LoginActivity and then calls
finish() on itself (At this point
LoginActivity is the only Activity
on the stack) - User press “Home” button, stopping
LoginActivity - User launches the app again
When the app is launched for the 2nd time, two things can happen:
- LaunchActivity starts, finishes
itself and then STARTS LoginActivity - 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.
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.