0

I have a instance of FragmentManager (variable frgManager), I replace to new fragment by:

 // Fragments all use the same container
 frgManager.beginTransaction().replace(containerId, nextFragment, MyTag).commit();

Let's say I have three fragments A, B, C,

the app show fragments in the sequence of A-->B-->C. Everytime show next fragment, I call the code above.

The problem is after C is shown, I close C, then B is shown in foreground, but the onResume() of A is also called. Why? How to avoid that because I expect only B's onResume() get called in this case.

1 Answer 1

2

frgManager.beginTransaction().replace(containerId, nextFragment, MyTag).addToBackStack().commit();

Use addToBackStack when creating all of your fragments. This way, only 1 can be active at once.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.