android – Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP之间有什么区别吗? Intent.FLAG_ACTIVITY_SINGLE_TOP

android – Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP之间有什么区别吗? Intent.FLAG_ACTIVITY_SINGLE_TOP,第1张

概述我想知道,2代码有什么区别? newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIV 我想知道,2代码有什么区别?

newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_top);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_top | Intent.FLAG_ACTIVITY_SINGLE_top);

FLAG_ACTIVITY_CLEAR_top

If set,and the activity being launched is already running in the
current task,then instead of launching a new instance of that
activity,all of the other activitIEs on top of it will be closed and
this Intent will be delivered to the (Now on top) old activity as a
new Intent.

FLAG_ACTIVITY_SINGLE_top

If set,the activity will not be launched if it is already running at
the top of the history stack.

我的理解是

> FLAG_ACTIVITY_CLEAR_top – 清除顶部的所有活动,并在同一任务堆栈中阻止同一活动的多个实例.
> FLAG_ACTIVITY_SINGLE_top – 在同一任务堆栈中防止同一个Activity的多个实例.

如果我的理解是正确的,那就不是Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_top | Intent.FLAG_ACTIVITY_SINGLE_top似乎多余了?

我们可以写Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_top?

解决方法 FLAG_ACTIVITY_CLEAR_top将创建一个新活动并关闭其他活动. FLAG_ACTIVITY_SINGLE_top将打开/重新打开该活动,具体取决于该活动是否已启动. 新的意图将在onNewIntent方法中接收,在这两种情况下,但第一个将破坏其他活动.我们需要想象有一个堆栈. 该堆栈由您开始活动的订单组成.想想那个场景.启动活动A,然后启动活动B,然后启动活动C. 堆栈就是这样的: _活动C. _活动B. _活动A. 然后,如果您启动活动A与FLAG_ACTIVITY_CLEAR_top,则活动A顶部的所有活动将被关闭,意图将在NewIntent上传递. 总结

以上是内存溢出为你收集整理的android – Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP之间有什么区别吗? Intent.FLAG_ACTIVITY_SINGLE_TOP全部内容,希望文章能够帮你解决android – Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_CLEAR_TOP之间有什么区别吗? Intent.FLAG_ACTIVITY_SINGLE_TOP所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125426.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存