Multiple Activity Instances and FLAG_ACTIVITY_REORDER_TO_FRONT

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

Now C0 creates the intent with FLAG_ACTIVITY_REORDER_TO_FRONT and triggers action 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 the foreground, A0 or A1? Will the task stacks become A0, B0, C0, A1 or A1, B0, C0, A0?

Thanks.

+4
source share
1 answer

Empirical evidence suggests that it brings the most recent instance to the fore. In your example, if the activity stack starts as follows:

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

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

 A0, B0, C0, A1 

When you use this flag, Android searches for an instance of this activity (starting from the front of the task and scanning it back / the root of the task). The first copy that he finds will be brought to the fore. If he does not find any instance in the action stack, he will create a new one.

+2
source

Source: https://habr.com/ru/post/1339082/


All Articles