您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页Android的Intent.FLAG_ACTIVITY_CLE

Android的Intent.FLAG_ACTIVITY_CLE

来源:二三四教育网

今天写代码遇到了一个问题:

当 B - A - B 跳转的时候,使用Intent的FLAG_ACTIVITY_CLEAR_TOP会让第一个B和第二个A,destory掉,但是当B - A - C跳转的时候不会调用B和A的destory。

查看API文档才发现原因,所以这里记录一下避免下次忘记了:

public static final int FLAG_ACTIVITY_CLEAR_TOP

Added in [API level 

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.

如果设置这个属性,是当要启动的Activity已经存在当前Task中,才会在启动的时候销毁其他的Activity。

所以上面当A跳C的时候不满足此条件。

当然如果想实现这个效果可以使用:

it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);

不过此方法要求最低API为11

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务