Last active
October 26, 2020 12:15
-
-
Save artem-zinnatullin/6916740 to your computer and use it in GitHub Desktop.
Android support library onActivityResult() bug fix for nested fragments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} | |
} | |
} |
It does not work every time for nested fragment managed by FragmentPagerAdapter
Sorry for that, it works well when using fragment.getParentFragment().startActivityForResult instead of fragment.startActivityForResult. thanks
thank you it is working well.
Thanks a lot man, you saved me from writing poor code. :)
This was really helpful, thanks
Where to put this code inside fragment or child fragments.....
Please help me.... It's urgent.
How to use with in child fragment onActivityResult
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
Are u telling that i just want to use this code in my onActivityResult() method?right?