How to reorder singleTask activity without creating new one?

221 Views Asked by At

I have 2 activity (Activity A and Activity B)

Activity A is singleTask and Activity B has standard launch mode.

When application started with Activity A and launch mode is singleTask, now from activity A start new activity B on button click.

So Stack is Activity A, B

Now wanted to reorder Activity A which is single task from Activity B but it's finishing Activity B first and then create new Activity A.

So stack at the momemnt is only Activity A.

What I've tried from Activity B.

val intent = Intent(this, ActivityA::class.java)
intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
startActivity(intent)

Problem: Without finishing Activity B required to reorder Activity A with launch mode singleTask.

Appreciated in advance.

1

There are 1 best solutions below

0
David Wasser On

You cannot reorder an Activity with singleTask launch mode to the front of the stack. An Activitywith singleTask launch mode is by definition the root Activity in a task.

Why would you want to do this? If you've configured the Activity as singleTask, you have told Android that you want this Activity to be launched as the root of a task. Why would you want to reorder this Activity to the front of the task? If the Activity can exist in the task somewhere other than the root, you shouldn't define it as singleTask!