1

I have some trouble with understanding of singleTop flag with launching Activity.

In my app i have 2 tasks :

Task 1 : A,B,C,D

Task 2 : X,Y,Z

All activities is a "standard" mode for launch except Activity D - she has "singleTop".

Both tasks is running.

Task1 [A,B,C,D]
Task2 [X,Y,Z]

Now is Z activity is opened. How will looks my stack if i run activity D from activity Z?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • Take look on this thread http://stackoverflow.com/questions/3268962/when-is-it-necessary-to-use-singletop-launchmode-in-an-android-widget-or-applica – mohammed momn Feb 11 '14 at 21:37
  • @mohammedmomn so my Task2 will have a stack XYZD ? – Sergey Shustikov Feb 11 '14 at 21:38
  • How do you have 2 tasks? Why do you have 2 tasks? I hope you realize that having multiple tasks in your application creates a lot of problems with navigation. Also, if the user goes to the recent tasks list, will they be able to navigate back to each of your tasks? – David Wasser Feb 11 '14 at 23:00
  • @DavidWasser 2 tasks it means that 2 apps in different tasks. – Sergey Shustikov Feb 12 '14 at 16:33

1 Answers1

1

Assuming that there are actually 2 different applications (as you stated in your comment) and activity D has no specific android:taskAffinity defined in the manifest, then the following will happen:

  • If Activity Z launches Activity D without any special Intent flags, a new instance of Activity D will be launched into Task 2, so that the Activity stack in Task 2 will contain [X,Y,Z,D]

  • If Activity Z launches Activity D and sets Intent.FLAG_ACTIVITY_NEW_TASK when launching it, Task 2 will go to the background, Task 1 will be brought to the foreground, onNewIntent() will be called on the existing instance of Activity D in Task 1 and then onResume() will be called on the existing instance of Activity D in Task 1. A new instance of Activity D will not be created.

David Wasser
  • 93,459
  • 16
  • 209
  • 274