Android启动模式LaunchMode
2017-08-31 03:13
597 查看
Intent.FLAG_ACTIVITY_CLEAR_TOP 清除该activity上的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. **/
如果当前栈里有这个activity的实例的话,会清除上面所有的activity并带上这个intent.
举例:依次启动A、B、C、D,D带Intent.FLAG_ACTIVITY_CLEAR_TOP启动B的话,C和D都会被清除,而D会收到这个Intent.
[b]结论:[/b]
关于B会不会新建有两种情况:
1. 当B是默认的standard(可以创建多个实例‘multiple’)模式下,B会被创建,Intent正是启动的Intent
检测是否有某个Flag用解包的方式 ((Intent.FLAG_ACTIVITY_CLEAR_TOP & intent.getFlags()) != 0)
2. 不会新建的情况
1) 当B是其他任意启动模式时候,都不会被新建,onNewIntent会被调用带有这个Intent
2) standard模式下(其他模式查看上一条说明)设置了Intent.FLAG_ACTIVITY_SINGLE_TOP
效果同上。
3. Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_NEW_TASK结合比较有意思的一个点,
当B是singleInstance的时候,可以把B带到栈顶而不会清掉C和D。在特定场景比如通知栏点击打开某个页面非常有用。
[b]建议[/b]
遇到启动模式相应的问题一定要注意目标activtiy本来设置的lauchmode,因为lauchmode也会影响结果,所以看到网上相关问题答案比较混乱,多种混用的话只能具体情况具体分析
遇到问题多注意源码注释,关于使用情况源码注释一般总结的非常全面。
相关文章推荐
- Android开发之Activity launchMode启动模式
- Android LaunchMode四种启动模式详细介绍
- Android Activity Launch Mode 启动模式详解
- 【Android基础】Activity的启动模式(android:launchMode)
- android中的四种启动模式launchMode
- Activity设置启动模式android:launchMode="singleInstance" 按home键后会销毁
- Android 4种启动模式launchMode
- Android android:launchMode=“singleInstance”启动模式设置单例 页面跳转黑屏
- android activity 启动模式 ==> launchmode
- android launchmode(四种启动模式)应用场景及实例
- Android Activity启动模式(android:launchMode="")
- Activity的启动模式(android:launchMode)
- 【Android基础】Activity的启动模式(android:launchMode) .
- android launchmode(四种启动模式)应用场景及实例
- 【Android基础】Activity的启动模式(android:launchMode)
- android:launchMode--四种启动模式
- Android初学习 - Activity启动模式(lauchMode)总结
- 将启动页的android:launchMode设置成singleTask
- Android总结篇系列:Activity启动模式(lauchMode)
- 【转】Android总结篇系列:Activity启动模式(lauchMode)