Answer the question
In order to leave comments, you need to log in
How to close all sequentially opened fragments one after another?
There are several fragments.
Each one is pushed onto the stack when opened. The following code is used to display each fragment:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
transaction.replace(containerId, fragment);
transaction.addToBackStack(null);
transaction.commitAllowingStateLoss();
Answer the question
In order to leave comments, you need to log in
You are adding fragments to the stack incorrectly. The method transaction.addToBackStack(null)
you pass null
to must accept an identifier string by which you can uniquely identify the given fragment on the stack. You can return to any fragment marked like this like this:
where name is just the same identifier string.
calling
FragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
you can clear the entire stack of fragments.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question