Not working FLAG_ACTIVITY_NEW_TASK with taskAffinity

516 views Asked by At

My application has 2 launch activities A and B. Activity B has taskAffinity="Task2".

1) Launch B from android menu, change some fields there, then press home button.

2) Launch activity A. From A, launch B with flag FLAG_ACTIVITY_NEW_TASK. This fields are not saved. Thats the problem.

Now there is this:

  1. MainTask: Task2:B(first)
  2. MainTask:A Task2:B(first)
  3. MainTask:A Task2:B(first) -> B(second)(OnTop)

But I want this:

  1. MainTask: Task2:B(first)
  2. MainTask:A Task2:B(first)
  3. MainTask:A Task2:B(first)

Help me please. I want to apologise in advance, this is my first post and my english is not good.

I found answer. In manifest file need to write android:launchMode="singleTop" for activity B.

1

There are 1 answers

0
Xingchen Liu On

You can set

android:launchMode="singleTop"

or

android:launchMode="singleTask"

or

android:launchMode="singleInstance"

depending on your actual need. All of the three will achieve what you want.