Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple activity instances and FLAG_ACTIVITY_REORDER_TO_FRONT

Suppose the current task stacks has four activity instances, A0, A1, B0, C0, with C0 at the top of the stack. A0, A1 are instances of Activity A, B0 is instance of Activity B, and C0 is instance of Activity C0.

Now C0 creates an intent with FLAG_ACTIVITY_REORDER_TO_FRONT and starts Activity A:

Intent intent = new Intent(this, A.class);
intent.setFlag(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

My question is, which instance will be brought to front, A0 or A1? Will the task stacks become A0, B0, C0, A1 or A1, B0, C0, A0?

Thanks.

like image 607
Kai Avatar asked Nov 05 '22 03:11

Kai


1 Answers

Empirical evidence says that it brings the most recent instance to the front. In your example, if the activity stack starts out like this:

 A0, A1, B0, C0 (front of task)

and C0 starts A with Intent.FLAG_ACTIVITY_REORDER_TO_FRONT, instance A1 is brought to the front and the activity stack now looks like this:

A0, B0, C0, A1

When you use this flag, Android looks for an instance of this activity (starting from the front of the task and scanning to the back/root of the task). The first instance it finds will be brought to the front. If it doesn't find any instance in the activity stack it will create a new one.

like image 189
David Wasser Avatar answered Nov 15 '22 11:11

David Wasser