Android启动模式LaunchMode
来源:互联网 发布:js实现中奖后彩带特效 编辑:程序博客网 时间:2024/06/08 00:11
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会不会新建有两种情况:
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。在特定场景比如通知栏点击打开某个页面非常有用。
建议
- 遇到启动模式相应的问题一定要注意目标activtiy本来设置的lauchmode,因为lauchmode也会影响结果,所以看到网上相关问题答案比较混乱,多种混用的话只能具体情况具体分析
- 遇到问题多注意源码注释,关于使用情况源码注释一般总结的非常全面。
- android启动模式 launchMode
- Android 启动模式 launchMode
- android:launchMode 启动模式
- Android启动模式LaunchMode
- Android 启动模式launchMode说明
- Android 启动模式(launchMode)
- Android的启动模式(android:launchMode)
- Android Activity的启动模式(android:launchMode)
- 【Android】Activity的启动模式(android:launchMode)
- Activity的启动模式(android:launchMode)
- Activity的启动模式(android:launchMode)
- Activity的启动模式(android:launchMode)
- Activity的启动模式(android:launchMode) 总结
- Activity的启动模式(android:launchMode)
- Activity的启动模式(android:launchMode) 小结
- android:launchMode--四种启动模式
- Android 4种启动模式launchMode
- Activity的启动模式(android:launchMode)
- LINUX内核参数注释与优化SGECVPSJUPSJU
- ELK5.3+KAFKA集群配置ONVUWSWS
- TCP协议的3次握手与4次挥手过程详解
- SQLServer--常用的系统存储过程使用
- centos开启ssh服务
- Android启动模式LaunchMode
- 二维码的生成细节和原理
- Leetcode 162. Find Peak Element
- SQLServer--常用的扩展存储过程使用
- c# LINQ的使用
- Java抽象类和接口的区别
- css用margin :0 auto 后依旧无法对齐
- Beginning Spring学习笔记——第6章(二)使用Spring进行声明式事务管理
- Kaggle:数据践行者的好去处(如何开展大数据的实践?)