single task Activity不能使用startActivityForResult解释
2016-11-22 11:02
435 查看
问题描述:
从Activity A中使用startActivityForResult启动Activity B(Manifest中Activity的声明包含
void onActivityResult(int requestCode, int resultCode, Intent data),系统返回resultCode=RESULT_CANCELED。在B中的setResult也没有任何意义了。
Logcat输出如下的信息:
Activity is launching as a new task, so cancelling activity result.
看了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
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不能这样设置:
去掉B 中的如上设置,运行正常。
因此,对于singInstance或singleTask的Activity只能采用其他的方式来传递数据。
这两个LaunchMode标识只能用在startActivity()的方法中,而不能使用在startActivityForResult方法中。因为从Task的角度看,Android认为不同Task之间的Activity是不能传递数据的。所以也不会有有用的result返回。
详细解释:
http://blog.csdn.net/sodino/article/details/22101881
从Activity A中使用startActivityForResult启动Activity B(Manifest中Activity的声明包含
android:launchMode=
"singleTask"),但是调用startActivityForResult后马上调用A里面的protected
void onActivityResult(int requestCode, int resultCode, Intent data),系统返回resultCode=RESULT_CANCELED。在B中的setResult也没有任何意义了。
Logcat输出如下的信息:
Activity is launching as a new task, so cancelling activity result.
看了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_MAINor
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" [/code] |
因此,对于singInstance或singleTask的Activity只能采用其他的方式来传递数据。
这两个LaunchMode标识只能用在startActivity()的方法中,而不能使用在startActivityForResult方法中。因为从Task的角度看,Android认为不同Task之间的Activity是不能传递数据的。所以也不会有有用的result返回。
详细解释:
http://blog.csdn.net/sodino/article/details/22101881
相关文章推荐
- Activity设置singleInstance后不能启用startActivityForResult()进行数据回调
- Activity设置singleInstance后不能启用startActivityForResult()进行数据回调
- Android Exception 5(startActivityForResult & singleTask)
- Android非5.0系统下singleTask singleInstance startActivityForResult
- Android singleTask或singleInstance与startActivityForResult冲突解决
- startactivityforresult的使用,和singleTask不能使用的问题
- Activity设置singleInstance后不能启用startActivityForResult()进行数据回调
- Activity设置singleInstance后不能启用startActivityForResult()进行数据回调
- Activity设置singleInstance后不能启用startActivityForResult()进行数据回调
- 在使用startActivityForResult时设置的SingleTop不起作用
- 关于Activity和Fragment同时使用startActivityForResult的问题
- Android中startActivityForResult的一种特殊使用
- 避免使用startActivityForResult
- Android开发中使用startActivityForResult()方法从Activity A跳转Activity B出现B退出时A也同时退出的解决办法
- startActivityForResult 使用详解
- (转)android中使用startActivityForResult回传数据
- Android startActivityForResult的使用
- Tabhost中子Activity使用startActivityForResult后获取不到回调值问题的解决办法
- TabHost中使用startActivityForResult无法接收返回值的解决方案[转]
- Tabhost中子Activity使用startActivityForResult后获取不到回调值问题的解决办法