Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: keep task's activity stack after restart from HOME

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?

like image 381
alex2k8 Avatar asked Jan 13 '10 23:01

alex2k8


People also ask

How do I get my old Android activity back?

In the second activity, the back button at the top left can be used to go back to the previous activity.

When an activity is at the top of the stack it is the activity that is receiving user input?

onResume() This method is always called just before the activity starts interacting with the user. At this point, the activity is at the top of the activity stack, with the user input going to it. It is always followed by the onPause() method.


3 Answers

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)
like image 197
alex2k8 Avatar answered Sep 30 '22 18:09

alex2k8


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.

like image 34
Vit Khudenko Avatar answered Sep 30 '22 16:09

Vit Khudenko


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

like image 30
Shayan_Aryan Avatar answered Sep 30 '22 18:09

Shayan_Aryan