Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...