Android – the fragment startactivityforresult always returns resultcode 0 and intent null on the callback onactivityresult

I searched all similar posts about it, but I couldn't find a solution!

In my case, I have an activity a, which contains a fragment. I want to start a new activity B from this fragment, which should return some values to the fragment

On clip

startActivityForResult(mapIntent, ConstantsUtils.TOMAP_REQUEST_CODE);

On activity B, return data

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

On clip

@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 in the fragment is successfully called with the correct requestcode, but the resultcode is always 0 and intent is always null

I have no other onactivityresult implementation under activity a

In fact, I also try to start the activity getactivity(). Startactivityforresult (mapintent, constantsutils. Tomap_request_code) from the fragment; And implement onactivityresult on activity a, but it has the same, correct requestcode but wrong resultcode and intent

I am using Sherlock action bar, so my fragment is Sherlock listfragment, so I am using support library (R18)

Could you help me? thank you

resolvent:

The result code 0 is result_ CANCELLED.

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

A common reason to get this code is to start an activity in a new task (check the intent and manifest of the tag, which will lead to the start of the new task)

In addition, if you have a parent activity, you should set its result code instead of its children (try GetParent and set its result code if it is not null)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>