onActivityResult not being called in Fragment

Read more details in original post.

Description

FragmentActivity replace requestCode by modified one. After that, when onActivityResult() will be invoked, FragmentActivity parse higher 16 bits and restore index of original Fragment. Look at this scheme:

enter image description here

If you have few fragments at the root level there is no problems. But if you have nested fragments, for example Fragment with 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 it's FragmentManager. When we using nested fragments, there are child FragmentManager, which has own list of Fragments. So, it's necessary to save whole chain of indices, starting from root FragmentManager.

enter image description here

Solution

Compile this project and look at the CommonActivity.java.