androidandroid-fragmentsandroid-fragmentactivityback-stackfragment-backstack

PopBackStack but keep the first fragment in android


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


Solution

  • E.g. you can do following:

    P.S. There are other ways how to do what you want. It depends...