Skip to content

Instantly share code, notes, and snippets.

@artem-zinnatullin
Last active October 26, 2020 12:15
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save artem-zinnatullin/6916740 to your computer and use it in GitHub Desktop.
Save artem-zinnatullin/6916740 to your computer and use it in GitHub Desktop.
Android support library onActivityResult() bug fix for nested fragments
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// notifying nested fragments (support library bug fix)
final FragmentManager childFragmentManager = getChildFragmentManager();
if (childFragmentManager != null) {
final List<Fragment> nestedFragments = childFragmentManager.getFragments();
if (nestedFragments == null || nestedFragments.size() == 0) return;
for (Fragment childFragment : nestedFragments) {
if (childFragment != null && !childFragment.isDetached() && !childFragment.isRemoving()) {
childFragment.onActivityResult(requestCode, resultCode, data);
}
}
}
}
@asbadve
Copy link

asbadve commented Sep 12, 2014

Are u telling that i just want to use this code in my onActivityResult() method?right?

@zourb
Copy link

zourb commented Nov 16, 2014

It does not work every time for nested fragment managed by FragmentPagerAdapter

@zourb
Copy link

zourb commented Nov 16, 2014

Sorry for that, it works well when using fragment.getParentFragment().startActivityForResult instead of fragment.startActivityForResult. thanks

@Bhavdip
Copy link

Bhavdip commented Sep 24, 2015

thank you it is working well.

@nitinjain92
Copy link

Thanks a lot man, you saved me from writing poor code. :)

Copy link

ghost commented Nov 2, 2015

This was really helpful, thanks

@manzarhussain
Copy link

Where to put this code inside fragment or child fragments.....
Please help me.... It's urgent.

@manzarhussain
Copy link

How to use with in child fragment onActivityResult

@mlshv
Copy link

mlshv commented Apr 9, 2017

Thank you! You saved a lot of my time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment