getParentFragment() in fragments is returning null when fragment is popped out from backstack

1.5k views Asked by At

I have an activity containg framelayout, fragment A is hosted with getSupportFragmentManager() in this.

This fragment A hosts two more fragments which has recycler views in it -Fragment A1 and Fragment A2 using FragmentStatePagerAdapter. At this point of time i was able to get Parent Fragment using getSupportFragmentManager() in Fragment A1 and A2.

Click on recycler view item in A1 and A2 results in another Fragment say Fragment B that replaces Fragment A and adds it to backstack.

Now the problem comes here, when i press back button i was able to get the Fragment State A view but getSupportFragmentManager() is returning null for parent fragment in A1 and A2 fragments.

How should this method be used properly?

1

There are 1 answers

0
Suhaib Roomy On

Use getChildFragmentManager() in viewpager when the viewpager is nested inside a fragment.

adapter = new ViewPagerAdapter(getChildFragmentManager());