片段startActivityForResult总是返回结果code 0和意图空回调onActivityResult [英] fragments startActivityForResult always return resultCode 0 and intent null on callback onActivityResult

查看:739
本文介绍了片段startActivityForResult总是返回结果code 0和意图空回调onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找遍了,有关于它类似的帖子,但无法找到解决的办法!

I searched all over and there are similar posts about it, but can't find a solution!

我的情况是我有一个持有片段的活性的,并从该片段我要开始一个新的b活动应该返回一些值的片段。

My situation is I have an Activity A that holds a fragment, and from that fragment I want to start a new Activity B that should return some values to the fragment.

在片段

startActivityForResult(mapIntent, ConstantsUtils.TOMAP_REQUEST_CODE);

在活动B,返回数据。

Intent returnIntent = new Intent();
returnIntent.putExtra(SerializationConstants.isSearchSaved, mAbItemsShown.ordinal());
setResult (ConstantsUtils.SUCCESS_RETURN_CODE, returnIntent);
finish();

在片段

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

switch (requestCode) {

    case ConstantsUtils.TOMAP_REQUEST_CODE:

            if (resultCode == ConstantsUtils.SUCCESS_RETURN_CODE) {
              //do some stuff 
            }
    }
}

onActivityResult从片段成功调用,用正确的请求code,但结果code始终为0和意图总是空

onActivityResult from the fragment is successfully called, with the right requestCode but resultCode is always 0 and intent is always null

我在活动无其他onActivityResult实施

I have no other onActivityResult implementation under Activity A

其实,我也尝试从与片段开始活动 。getActivity()startActivityForResult(mapIntent,ConstantsUtils.TOMAP_REQUEST_ code); 贯彻onActivityResult在活动A,但它发生的一样,正确的请求code,但错误的结果code和意图

In fact, I also try starting the activity from the fragment with getActivity().startActivityForResult(mapIntent, ConstantsUtils.TOMAP_REQUEST_CODE); and implementing onActivityResult on Activity A but it happens the same, right requestCode but wrong resultCode and intent

我使用的是福尔摩斯操作栏,所以我的片段是一个SherlockListFragment所以我使用的支持库(R18)

I'm using Sherlock Action Bar so my fragment is a SherlockListFragment so I'm using the support library (r18)

您能帮我吗?谢谢

推荐答案

结果code 0 RESULT_CANCELLED

The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

也越来越此code的常见原因是推出一个新任务的活动(检查你的意图和明显的标志,这导致了一个新任务的开始)。

Also the common reason of getting this code is a launching an activity in a new task (check your intent and manifest for flags, which lead to the start of a new task).

此外,如果你有一个父活动,你应该设置的一组结果$ C $其子的C测试结果$ C $它℃,而不是(尝试的getParent 和如果不为空,高于设定的结果$ C $的是C)。

Also if you have a parent activity, you should set result code of it instead of set result code of its child (try to getParent and if it is not null, than set result code of it).

这篇关于片段startActivityForResult总是返回结果code 0和意图空回调onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆