android – onActivityResult() not called
Table of Contents
android – onActivityResult() not called
Option 1 :
If youre calling startActivityForResult()
from the Fragment
then you should call startActivityForResult()
and not getActivity().startActivityForResult()
, as it will result in Fragment
s onActivityResult()
.
If youre not sure where youre 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
}
I solved my problem by removing android:noHistory=true
from AndroidManifest.xml
.
android – onActivityResult() not called
I had same issue. My calling activity was singleInstance. Removing that solved my issue.