I have many nested fragments.
This is how I start activity for result:
startActivityForResult(Intent.createChooser(intent, "Title"), FILE_PICK);
I don't have onActivityResult
overriden anywhere else. I tried to call it in Activity A and it got called, but then even though I called super, it never came to Fragment D. Also tried to call onActivityResult
in MainFragment
and it never gets called there either.
The event is going to be received in the activity. To have it in Fragment D you have to propagate it.
On your parent activity override onActivityResult
and start calling the onActivityResult
of your fragments:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
List<Fragment> fragments = fragmentManager.getFragments();
if(fragments != null){
for(Fragment fragment : fragments){
fragment.onActivityResult(requestCode, resultCode, data);
}
}
}
In your parent fragment you have to do the same thing, but remember to use getChildFragmentManager
to get the fragment manager of the fragment
List <Fragment> fragments = getChildFragmentManager().getFragments();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With