Android的Intent.FLAG_ACTIVITY_CLEAR_TOP无效

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

当 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 1

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值