多个活动实例和FLAG_ACTIVITY_REORDER_TO_FRONT [英] Multiple activity instances and FLAG_ACTIVITY_REORDER_TO_FRONT

查看:53
本文介绍了多个活动实例和FLAG_ACTIVITY_REORDER_TO_FRONT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设当前任务堆栈有四个活动实例A0,A1,B0,C0,而C0在堆栈顶部. A0,A1是活动A的实例,B0是活动B的实例,而C0是活动C0的实例.

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.

现在C0使用FLAG_ACTIVITY_REORDER_TO_FRONT创建一个意图并开始活动A:

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);

我的问题是,哪个实例将出现在A0或A1的前面?任务堆栈会变成A0,B0,C0,A1还是A1,B0,C0,A0?

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?

谢谢.

推荐答案

经验证据表明,它会将最新实例带到了最前面.在您的示例中,如果活动堆栈是这样开始的:

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)

并且C0以Intent.FLAG_ACTIVITY_REORDER_TO_FRONT开头A,实例A1排在最前面,活动堆栈现在看起来像这样:

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

使用此标志时,Android将查找此活动的实例(从任务的开头开始,扫描到任务的后/根).它找到的第一个实例将被带到最前面.如果在活动堆栈中找不到任何实例,它将创建一个新实例.

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.

这篇关于多个活动实例和FLAG_ACTIVITY_REORDER_TO_FRONT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆