I am working on fragment transaction, and the backstack is like this:
fragA => fragB => fragC => fragD
I would like to return to fragA after back fromn the fragD
fragD => onBackPress => fragA
So, I tried code like:
getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
but it clear all the backstack , how can I keep the first fragment in the backstack? Thanks a lot
Mark my words, complete
FragmentTransaction
s are added to backstack not just a fragment, means even if you add and remove fragment in a single transaction callingpoBackStack()
will reverse the complete transaction. Passing a tag in its argument pops all the transaction till the tagged transaction or even pops the tagged transaction (in caseFragmentManager.POP_BACK_STACK_INCLUSIVE
added to the argument) So it's more about how you added it not how you removing it. See Performing Fragment TransactionsE.g. you can do following:
activity, and won't react on back button.
P.S. There are other ways how to do what you want. It depends...