调用startActivityForResult后onActivityResult立刻响应,返回当前页onActivityResult不响应的问题

来源:互联网 发布:淘宝店铺微淘二维码 编辑:程序博客网 时间:2024/05/17 10:57

转载于http://blog.csdn.net/mengliluohua_151/article/details/9951163


参考了网上的一些博客,找到了原因,在此感谢那些分享知识的好心人。

原因是在AndroidManifest.xml 中跳转到的页面我自己设置了Android:launchMode="singleTask",因为需要传值的 Activity 不容许设置该属性或者 singleInstance,或只能设为标准模式,不然将在 startActivityForResult()后直接调用 onActivityResult()。
解决办法:去掉跳转到的页面的lanchMode属性即可。
另外,requestCode值必须要大于等于0,不然,startActivityForResult就变成了 startactivity。


找到的一些资料:(摘抄自http://aijiawang-126-com.iteye.com/blog/1717326)

从SDK我们可以看到如下深奥的解释:http://developer.android.com/guide/topics/manifest/activity-element.html#lmode 
The other modes — singleTask and singleInstance — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications. 
从柯元旦的《Android 内核剖析》的第十章“Ams内部原理“10.1.3中有这样的一段话:请注意:SINGLE_TASK标识以及SINGLE_INSTANCE两个标识必须在r.result==0的条件中,即这两个标识只能用在startActivity()的方法中,而不能使用在startActivityForResult方法中。因为从Task的角度看,Android认为不同Task之间的Activity是不能传递数据的,所以不能使用NEW_TASK标识,但还是要调用forResult方法。

0 0
原创粉丝点击