1

Reading Google's own documentation here, they state starting an activity with the 'singleTask' launch mode will either start a new task with that activity as its root, or, if there already is a task with that activity in it, that entire task's stack is brought forward and the intent will be routed through the existing activity's onNewIntent method.

However, in regards to bringing entire task activity stacks forward, this image...

enter image description here

seems to show the green task with Activity Y as having 'singleTask' set. However, Activity Y is not the root. Activity X is, but that shouldn't be possible because if Activity X launched Activity Y, then wouldn't there be a third task with Activity Y at the root? (At first I thought perhaps Activity X launched Y with flags that overrode 'singleTask' but I don't see such flags.)

Also, that issue aside, it doesn't seem to explain what would happen if, prior to Activity 2 requesting Activity Y, Activity Y started a new Activity Z which is just a standard launch mode. Since Activity Y is 'singleTask', not 'singleInstance', Activity Z would appear in the same task as Activity Y on the top of its back-stack.

So what happens to Z when Activity 2 requests Y? Does that bring X and Y forward, but destroy Z, meaning the Blue task just nuked an activity in the Green task's back-stack? ...or does it bring forward X, Y and Z, meaning even though you requested Y, you're now looking at Z?

At first I thought it was the former but the documentation for FLAG_ACTIVITY_CLEAR_TOP also explicitly states:

If the activity being started is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it are destroyed and this intent is delivered to the resumed instance of the activity (now on top), through onNewIntent()).

There is no value for the launchMode attribute that produces this behavior.

Also, same scenario. Activity 2 (Blue Task) launches Activity Y (Green task) bringing forward its back stack with it. The user hits the home button and re-launches the app that created the Blue stack. Does it jump back to Activity 2? If not, then that breaks the stance that for all intents and purposes (no pun intended), a task is an application.

So what am I missing?

Community
  • 1
  • 1
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286

0 Answers0