0

I have to be honest this is a question which is at present academic but I have searched extensively and cannot find anyone who describes the answer. It even caused me to have an awful night's sleep last night as it manifested itself in me dreaming about continually trying to find a white puppy but I was always unable to find the puppy. So you see, this is both technically and mentally a pretty serious issue.

So,

Let's say I have a Task stack of 3 activities, A, B, C. A has launch mode "singleTask", and let's make activities B and C launch mode "standard".

So, Task 1 is

A -> B -> C

Let's say I have a second Task which is composed of just 2 activities, X (the root activity with launch mode "standard") and a 2nd activity which is actually Activity A.

So, Task 2 is

X -> A

**Question : When activity X invokes activity A (which is defined launch mode "singleTask", what happens to the children of activity A on Task stack 1 (ie B and C) ??? When I invoke activity A, from activity X, do I end up with back stack : X -> A -> B -> C (ie activity C becomes displayed)

Or

X -> A (ie the previous children of Task A are removed from the front of the back stack)

Also, regardless of the answer above, if I were to "BACK" key all the way back through the stack for Task 2, what happens to the original Task 1's stack. Has it now become gobbled up by Task 2 and so no longer exists ?

I want to go for a big run today so the thought of another night searching for the white puppy is rather depressing.

Any response or a link would help.

The example given on the Android Dev section covers how ancestor activities of the "singleTask" activity are "merged" into the back stack of the Task which invokes the "singleTask" activity but unfortunately it does not describe what would happen to the children of the "singleTask" activity.

Many thanks in advance ladies and gents.

Paul.

Swati Garg
  • 995
  • 1
  • 10
  • 21
user1151685
  • 161
  • 8

1 Answers1

0

**Question : When activity X invokes activity A (which is defined launch mode "singleTask", what happens to the children of activity A on Task stack 1 (ie B and C) ??? When I invoke activity A, from activity X, do I end up with back stack : X -> A -> B -> C (ie activity C becomes displayed)

Or X -> A (ie the previous children of Task A are removed from the front of the back stack)

Neither would happen. Tasks are not mixed up, a activity may move to a task having same affinity.

So there would be two tasks now, Task 1 would have only activity A, and Task 2 would have only activity X. Activities B and C would be cleared from the Task 1.

Although, as discussed at the following links

1. Android: bug in launchMode=“singleTask”? -> activity stack not preserved,

2. Making activity singleTask destroys stack after returning? and

3. Issue 11160: Behaviour of launchMode=“singleTask” not as described,

if there is a bug then the Task 1 should has just brought to foreground with activities B and C.

if I were to "BACK" key all the way back through the stack for Task 2, what happens to the original Task 1's stack. Has it now become gobbled up by Task 2 and so no longer exists ?

So now the "Back" key behavior would be according to the new tasks, and as stated at Tasks and Back Stack

When the user presses the BACK button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored). Activities in the stack are never rearranged, only pushed and popped from the stack—pushed onto the stack when started by the current activity and popped off when the user leaves it using the BACK button. As such, the back stack operates as a "last in, first out" object structure.

Hope, it helps.

Community
  • 1
  • 1
Vasu
  • 4,862
  • 8
  • 42
  • 48