[Android]SingTask 与 onNewIntent
来源:互联网 发布:恒智it 编辑:程序博客网 时间:2024/06/05 15:30
在开发中经常会遇到这种情况,比如在主页面进入子功能页面,一步一步很多层,然后子功能完成,要退回主页面,这时候我们应该怎么处理?
其实合理运用Android的lunchMode就可以解决:
假设主页面是MainActivity, 子功能页面SubActivity1,SubActivity2…..
设置MainActivity 的lunchMode=singTask
(故名思意,就是让这个activity只存在与唯一一个task里)
SubActivity? 调用startActivity()启动MainActivity后,有这几种情况:
- 如果调用startActivity的SubActivity?与MainActivity在同一个task里,则移除MainActivity顶部所有activitys,不调用MainActivity的oncreate(因为它本身已经存在,只不过是推到栈顶),但会调用onNewIntent(Intent newIntent);
- 如果调用startActivity的SubActivity?与MainActivity在不同task里,则将MainActivity的栈整体移至启动task的栈顶,并如
1.
一样,移除MainActivity顶部activitys,调用onNewIntent(Intent newIntent); - 如果MainActivity不存在,则启动MainActivity,同Activity正常创建生命周期。
- OnNewIntent(Intent newIntent)注意事项;
在该方法中只是会传入一个intent,但是activity的Intent并不会被设置,所以要setIntent(intent)
后才能在Activity中获得需要的Intent;
0 0
- [Android]SingTask 与 onNewIntent
- Android启动模式与onNewIntent
- android onNewIntent
- android onNewIntent
- android onNewIntent
- android onNewIntent
- android onNewIntent
- Android onNewIntent
- android onNewIntent
- android onNewIntent
- android onNewIntent
- android onNewIntent
- Android onNewIntent
- android onNewIntent
- android--onNewIntent
- android onNewIntent
- android onNewIntent()
- android onNewIntent
- Makefile编译选项CC与CXX/CPPFLAGS、CFLAGS与CXXFLAGS/LDFLAGS
- android代码设置背景setBackgroundColor无效
- 2012全国优秀IC和电子产品解决方案
- CodeForces 371C Hamburgers (二分)
- 创建Material Design风格的Android应用--使用自定义动画
- [Android]SingTask 与 onNewIntent
- HDOJ 汉字统计
- tyvj p1036 统计数字
- UVALive - 4327 Parade DP + 优先队列
- 命运(dp)
- mac远程win8
- 代码重构的时机与要点
- ANDROID L——Material Design详解(动画篇)
- 梳理一下最近一年读过的书籍列表书单以及学习计划