3

I would like to launch an activity (say abc) in a different task every time I launch the activity with flag_new_task.

How do i set a different affinity to the activity each time I launch it.

thanks,

Adilmo
  • 117
  • 1
  • 9
  • 1
    See a very good EXPLANATION: https://www.slideshare.net/RanNachmany/manipulating-android-tasks-and-back-stack – StepanM Feb 06 '18 at 15:51

1 Answers1

4

If you set both the flags Intent.FLAG_ACTIVITY_MULTIPLE_TASK and Intent.FLAG_ACTIVITY_NEW_TASK when launching the activity, then Android will create a new task every time you do it.

BIG WARNING

HOWEVER, if you create many tasks like this using the same activity, there is no way for the user to return to a specific task by long-pressing on the HOME button. You need to make sure that you don't confuse the user when you do this.

See

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_MULTIPLE_TASK

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Hi David, Can I switch between these tasks programatically – Adilmo Oct 01 '12 at 09:35
  • I don't think so. This isn't really a good model for Android programming. Can you explain why you want to do this? There is probably a different/better approach available. – David Wasser Oct 04 '12 at 08:55
  • From a service I want to create different task stack for every request I recieve through service. For every user app accessing the service, there will be separate task stack. Now, within service I would like to manage different task stacks invoked – Adilmo Oct 08 '12 at 10:19
  • You may be able to manage this programmatically by using `ActivityManager`. There are methods like `moveTaskToFront()` and `getRunningTasks()` that you can use. I still don't understand why you would want to do this, though. Good luck! – David Wasser Oct 08 '12 at 12:59
  • Thanks david ... but moveTaskToFront() is only available after api 11 ... Can I achieve the same functionality prior to api 11 ? – Adilmo Oct 09 '12 at 07:02
  • Sorry, not that I know of. You may be able to access some private API fdr this, but I would have to dig through the source code to figure that out. – David Wasser Oct 09 '12 at 09:14