Skip to content Skip to sidebar Skip to footer

Fragment Onresume() And Backstack Issue

I am stuck with situation for resuming my fragment when I am coming back from another fragment. Scenario : I have a Fragment A. Now I am opening multiple fragment with in Fragment

Solution 1:

Launch fragment A1, A2, A3 with childfragment manager from fragment A and launch fragment B with main fragment manager.

For Example : To perform any fragment operation we have two fragment manager, If you are performing any fragment operation within a fragment you should use getChildFragmentManager() inplace of getSupportFragmentManager().

Now here, to launch fragment A1, A2 and A3 you should use getChildFragmentManager() and When launching fragment B you should use getSupportFragmentManager(). So when you press back from fragment B you will get onResume callback in fragment A.

Solution 2:

When you have added your fragment B, have you added the transaction to the backstack with this command: addToBackstack(null); by this way, you can restore the previous state when you press back on fragment B and return to fragment A.

Post a Comment for "Fragment Onresume() And Backstack Issue"