onActivityResult() not called

onActivityResult called but using wrong intent reference to get data from result intent :

getIntent().getStringExtra("teamName")

Replace with this :

data.getStringExtra("teamName")

Here data is result intent.

Akash Moradiya

Option 1 :

If you're calling startActivityForResult() from the Fragment then you should call startActivityForResult() and not getActivity().startActivityForResult(), as it will result in Fragment's onActivityResult().

If you're not sure where you're calling on startActivityForResult() and how you will be calling methods.

Option 2:

Since Activity gets the result of onActivityResult(), you will need to override the Activity's onActivityResult() and call super.onActivityResult() to propagate to the respective Fragment for unhandled results codes or for all.

If above 2 options do not work, then refer option 3 as it will definitely work.

Option 3 :

Explicit call from Fragment to onActivityResult() function as follows

In parent Activity class, override the onActivityResult() and even override the same in Fragment class and call as the following code.

In parent class:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dualPane);
    fragment.onActivityResult(requestCode, resultCode, data);
}

In child class:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   //in fragment class callback
}
Android Dev

I solved my problem by removing android:noHistory="true" from AndroidManifest.xml.

I had same issue. My calling activity was 'singleInstance'. Removing that solved my issue.

I just had the same issue and I'm surprised none of the solutions I've looked at have mentioned the following:

The value of the constant RESULT_OK is -1, and if you give the value of 1 in the method setResult, then the resultcode wouldn't be equal to the RESULT_OK and the condition wouldn't get processed. I hope someone finds this helpful.

I had the same issue and I solved that by adding these parameters to activity:

AlwaysRetainTaskState = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop

After referring answer of @spgodara.

I have below AndroidManifest.xml for my SecondActivity class:

<activity android:name=".SecondActivity"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@style/AppThemeHome"
        android:windowSoftInputMode="adjustResize"/>

I have put simple Toast to find when callback onActivityResult of MainActivity is being called. I found that is just called on create of SecondActivity (On opening of the SecondActivity). It's working fine on Redmi Note 3 device with Marshmallow, but not working on Kitkat device.

After removing below the line from AndroidManifest.xml deceleration mentioned above:

android:launchMode="singleTask"

and calling intent like below worked for me:

 Intent intent = new Intent(this, SecondActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivityForResult(intent, SECOND_ACTIVITY_REQUEST_CODE);

I had similar problem and my issue was about requestCode parameter which was set to -1 in startActivityForResult method. So when I changed requestCode value to 1 or 0 onActivityResult started getting called.

Removed this line and its working fine.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Thanks for hint.

After reviewing pradip tilala's answer, I have solved my problem by removing below line from AndroidManifest.xml

android:noHistory="true"