首页 > 移动平台 > 详细

Android singleTask或singleInstance与startActivityForResult冲突解决

时间:2014-02-11 00:55:56      阅读:464      评论:0      收藏:0      [点我收藏+]

看了startActivityForResult的文档中有下面关键一句:

For example, if the activity you
     * are launching uses the singleTask launch mode, it will not run in your
     * task and thus you will immediately receive a cancel result.


Note that this method should only be used with Intent protocols that are defined to return a result. In other protocols (such as Intent.ACTION_MAIN or Intent.ACTION_VIEW), you may not get the result when you expect. For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result. 

也就是说B不能是单例或单任务启动模式,即launchMode不能这样设置:

android:launchMode="singleInstance"
android:launchMode="singleTask"

去掉B 中的如上设置,运行正常。

因此,对于singInstance或singleTask的Activity只能采用其他的方式来传递数据。

这两个LaunchMode标识只能用在startActivity()的方法中,而不能使用在startActivityForResult方法中。因为从Task的角度看,Android认为不同Task之间的Activity是不能传递数据的。所以也不会有有用的result返回。

Android singleTask或singleInstance与startActivityForResult冲突解决

原文:http://blog.csdn.net/forlong401/article/details/19047735

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!