AndroidHacker
AndroidHacker

Reputation: 3596

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 A say : A1, A2, A3 ... using a frame layout.

Now I am initiating a new Fragment say Fragment B from one of A1/A2/A3 ...

I am performing some action over Fragment B and now when I Pop Out my Fragment B then I am not able to get onResume() of Fragment A

Just need to get onResume() while I get back from Fragment B

Any help over this needed!

Highly appreciated!

Thanks.

Upvotes: 4

Views: 379

Answers (2)

AK Ali
AK Ali

Reputation: 162

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.

Upvotes: 1

fab
fab

Reputation: 790

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.

Upvotes: 0

Related Questions