

Actually, I just like the default back stack behavior.

So when I launch A, C, and then B, the stack looks like this: | |Īnd when I press the 'back' button, B is destroyed and C is resumed.īut, when I launch fragment A a second time, instead of resuming from back stack, it is added at the top of the back stack | |īut I want to resume A and destroy all fragments on top of it (if any). Every fragment is attached to the activity, and is saved to the back stack without any problem. Replacing/Adding: FragmentTransaction ft = getSupportFragmentManager().beginTransaction() I am adding the fragment to an activity like this:ĭeclaring and initializing: Fragment A = new AFragment() I have three instances of Fragment that are initialized at the top of the class. Var fragmentManager = () įragmentManager.Replace(Resource.Id.frameLayout1, fragment) įragmentManager.I am learning how to use fragments. This is my function for replacing fragments: public void ReplaceFragment(Fragment fragment) PopBackStackImmediate() for every fragment in backstack but the problem persists. I have tried multiple approaches such as a while loop with a. Explanation: MainFragment -> Fragment A -> Fragment B (this is added to backstack) -> Fragment C -> MainFragment (clear backstack ). The problem: After Fragment C is replaced with MainFragment, if the user presses the back button all the other fragments show up. This is because when there are multiple fragments in the backstack the application starts to perform poorly. This is because when there are multiple fragments in the backstack the application starts to perform poorly.Įxplanation: MainFragment -> Fragment A -> Fragment B (this is added to backstack) -> Fragment C -> MainFragment (clear backstack ). In my application I have a MainActivity with multiple fragments, the problem is I want to clear the backstack after replacing a specific fragment.
