views:

204

answers:

1

I have the following activity structure in my application

A simple "splash screen" activity is started when the application is fired up (let's call it "Splash"). This activity starts the main activity when the user presses a button (I will call it "Main").

Main can in turn start two activities from the menu. The first activity presents a simple form (let's call this one "Form"), the second is a MapActivity that presents a map (it is called "Map").

Main, Form, and Map are declared exactly the same in the manifest:

<activity android:name="fully qualified activity class"
        android:screenOrientation="landscape"
     android:configChanges="keyboard|keyboardHidden|orientation"
    >
    <intent-filter>
        <action android:name="android.intent.action.DEFAULT" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

When Main is active and I start Form and press "back", Main comes up again. Pressing "back" again brings up "Splash". Nothing strange here.

Now comes the strange part: when I am in Main, start Map, and press "back", Main comes up as expected. But pressing "back" again just restarts Main. A second press on "back" is needed to bring me back to Splash!

So it seems that starting the Map activity somehow results in Main ending up on the activity stack twice while starting the Form activity does not!

Both Form and Map are started like this:

startActivity(new Intent(this, MyActivity.class));

I don not catch the back key in any activity.

Any clues on what is going on or how to debug this?

A: 

I think I have seen this behavior before in one of my projects. Try setting the launchMode property of your launcher activity ( in your case Splash ) to - android:launchMode="singleTask" in the manifest file.

This should help clarify: http://developer.android.com/guide/topics/fundamentals.html#acttask

jeremynealbrown