9

My application has two activities, that I start in this order:

HOME > A > B

Now I press HOME and launch "A" again. I would like to see activity "B" on a top of "A", but instead I get "A" - so the activity stack is cleared.

Manifest:

<activity android:name=".activity.A" android:label="A" android:alwaysRetainTaskState="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<activity android:name=".activity.B" android:label="B">
    <intent-filter>
    </intent-filter>
</activity>

What should I do?

alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • Are you sure you're getting A and not B, or is your `android:label` for `.activity.B` a typo in the question? – Christopher Orr Jan 13 '10 at 23:49
  • Ah, this is a typo for .activity.B label (just fixed). I still see A while expect B. – alex2k8 Jan 14 '10 at 00:12
  • 1
    what you want is standard behavior, so perhaps there is some small typo or bug elsewhere. try "exiting" the app completely before testing this out, that is launch it and press back until the stack is clear, then relaunch? – James Jan 14 '10 at 00:39
  • Than you guys for your help, you gave me confidence :-) – alex2k8 Jan 14 '10 at 00:52

3 Answers3

10

I figured out what is wrong...

The config is right, but I started application for debugging from Eclipse, this was the issue.

Case # 1.

Debug > A > B > HOME > A
Get: A (stack is cleared)

Case # 2.

Debug > A > BACK > A > B > HOME > A
Get: B (stack preserved)

Case # 3.

A > B > HOME > A
Get: B (stack preserved)
alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • Ahh, interesting! There have been a lot of questions like this in the past day or two, so maybe that's the answer for some of them :) – Christopher Orr Jan 14 '10 at 00:57
  • Note that this behaviour has been fixed in the 0.9.6 release of the ADT plugin for Eclipse. You can now happily launch your apps from Eclipse and get the same behaviour as on a device. – Christopher Orr Mar 14 '10 at 14:48
2

It's not that complex. You just need to manipulate the manifest.

AndroidManifest.xm

<activity
     android:name=".MainActivity"
     android:alwaysRetainTaskState="true"
     android:exported="true"
     .
     .
     .

Read about the 'android:exported' & 'android:alwaysRetainTaskState' here:

android:exported

android:alwaysRetainTaskState

Shayan_Aryan
  • 2,002
  • 1
  • 29
  • 31
2

We have discovered this is a known Android issue - it has been officially tracked here and here.

Despite they say (did not checked) it has been fixed in the 0.9.6 release of the ADT Eclipse plugin I still can see this on a real device during the application OTA upgrade. At least this happens for Android 1.6, 2.0.1, 2.1 and 2.2.

We've created a workaround for this issue. Check it out here.

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91