4

In my application there is a behavior that I don't understand. I have the MainActivity A as SingleTask. It calls an Activity B that is SingleTask too. When I press the Home button in the second activity to open another application, and after that I try to go to my application mantaining Home button pressed i always go to Main Activity, and I want second activity to be opened mantaining the state that had when i press Home button.

I've tried setting then second activity to singleTop and it doesn't work.

Any help?

Macarse
  • 91,829
  • 44
  • 175
  • 230
Igor
  • 222
  • 4
  • 14

1 Answers1

4

The behaviour of activity back stack becomes quit weird when define main activity with singleTask at the same time:

<activity android:name=".MainActivity"
  android:launchMode="singleTask">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

What even worse is there is no clear explanation in the official dev guide regarding to this special use case. Some sections related to this topic are even self-contradictory.

Try using launchMode="standard" on your MainActivity A, and launchMode="singleTask" on your Activity B, which will give the expect behaviour you described.

Macarse
  • 91,829
  • 44
  • 175
  • 230
yorkw
  • 40,926
  • 10
  • 117
  • 130
  • This just happened to me and your explanation helped me figure it out. For me, I had to make both the "caller task" and the destination task both have anything but singleTask or singleInstance. Once I did that, it worked. It's explained in the dev docs, but in a way that would be hard to catch even for a Computer Science major – Joe Plante Oct 05 '12 at 17:53