Activity栈清空

本文详细介绍了Android中清空Activity栈的多种方法,包括clearTaskOnLaunch属性的使用,FLAG_ACTIVITY_CLEAR_TOP标志的应用,以及自定义Activity栈管理。同时,提到了不同启动模式在清空栈时的影响,如singleTask、singleInstance和singleTop,并提供了相关示例和注意事项。
摘要由CSDN通过智能技术生成

 

一、clearTaskOnLaunch:

clearTaskOnLaunch仅对根Activity有效

When the value is "true", every timeusers start the task again, they are brought to its root activity regardless ofwhat they were last doing in the task and regardless of whether they used theBackorHome button to leave it. When the value is "false", the task maybe cleared of activities in some situations (see thealwaysRetainTaskState attribute), but not always.

在AndroidManifest中,设置这个参数,当这个参数是true的时候,每次启动应用都会进入root activity 。不管之前是按back键的还是home键的。

二、用FLAG_ACTIVITY_CLEAR_TOP 实现清空Activity栈:

intent intent = new Intent(currentActivity,startActivity);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

startActivity(intent);

startActivity的启动模式为默认的。

应用首次启动的是startActivity,而且在启动后不finish掉,跳转到其他的activity。

这种方式可以实现当前栈中startActivity上面的所有activity被清空。

系统原理:

假设启动顺序是:startActivity-->A-->B-->C-->

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值