The activity hosting this fragment has its onActivityResult
called when the camera activity returns.
My fragment starts an activity for a result with th
Original post.
FragmentActivity
replaces requestCode
by a modified one. After that, when onActivityResult()
will be invoked, FragmentActivity
parses the higher 16 bits and restores the index of the original Fragment. Look at this scheme:
If you have a few fragments at the root level there are no problems. But if you have nested fragments, for example Fragment
with a few tabs inside ViewPager
, you guaranteed will face with a problem (or already faced it).
Because only one index is stored inside requestCode
. That is index of Fragment
inside its FragmentManager
. When we are using nested fragments, there are child FragmentManager
s, which have their own list of Fragments. So, it's necessary to save the whole chain of indices, starting from root FragmentManager
.
How do we resolve this issue? There is common workaround solution in this post.
GitHub: https://github.com/shamanland/nested-fragment-issue