Intent传值收不到的原因
来源:互联网 发布:零基础学c语言txt下载 编辑:程序博客网 时间:2024/05/17 22:34
背景:在特殊情况收不到!
1、android:launchMode=”singleTask” 这个时候收不到值
2、…
如果将activity的launchMode设置为singleTask,会发现收不到intent传递过来的值,这时候就需要使用到onNewIntent方法,在里面接收intent。
launchMode为singleTask的时候,通过Intent启到一个Activity,如果系统已经存在一个实例,系统就会将请求发送到这个实例上,但这个时候,系统就不会再调用通常情况下我们处理请求数据的onCreate方法,而是调用onNewIntent方法,
解决:回调 onNewIntent
protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent);//must store the new intent unless getIntent() will return the old one processExtraData(); }
同时,系统可能会随时杀掉后台运行的activity,那么系统就会调用onCreate方法,而不调用onNewIntent方法,因此需要在onCreate和onNewIntent方法中调用同一个处理数据的方法,如下所示:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); processExtraData(); }protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent);//must store the new intent unless getIntent() will return the old one processExtraData() } private void processExtraData(){ Intent intent = getIntent(); //use the data received here}
阅读全文
0 0
- Intent传值收不到的原因
- intent传值收不到 onNewIntent
- Activity复用的时候接受不到Intent数据的原因以及解决方法
- Activity singleTask Intent传值收不到
- 定位不到元素的原因
- BroadcastReceiver获取不到Intent的Extra
- 获取不到intent传递的数据
- 收不到邮件的原因浅析
- file_get_contents读取不到session的原因
- flex偶尔监听不到事件的原因
- viewpageindicator 加不到Eclipse Maven的原因
- tomcat服务器访问不到可能的原因;
- Android接收不到系统广播的原因
- $_POST取不到值的原因
- struts2 参数接收不到的原因
- android 开机广播接收不到的原因
- activity onActivityResult方法中拿不到intent的问题
- action带自定义的方法,但是访问不到的原因。
- 解压缩文件后无法删除
- 鸟哥的Linux私房菜(基础学习篇)笔记
- PHP下基于创蓝253接口的短信发送
- cmake 入门教程之编译一个源文件
- ArcGIS使用 -- 按feature选中
- Intent传值收不到的原因
- (转载)Linux OOM Killer个人总结
- Ubuntu 17.10/内核4.13.0 vmware 提示 Not Enough Physical Memory 解决方法
- bzoj 2789 [Poi2012]Letters 求逆序对
- Nginx的中间件架构
- Tomcat 7最大并发连接数的正确修改方法
- Ubuntu16.04 firefox安装flash player插件.
- Python操作Oracle数据库
- ElasticSearch优化系列二:机器设置(内存)