Reputation: 714
There is an Activity with 5 fragments (wizard).
StartFrag -(start)-> Frag1 -(next)-> Frag2 -(next)-> SubmitFrag
-(submit)-> SuccessFrag.
After Taping SubmitMore button on Success fragment, I want to remove Frag1, Frag2 and SubmitFrag from backstage and return to StartFrag. How to do that?
Upvotes: 3
Views: 5885
Reputation: 56
You could try this
FragmentManager fm = getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.add(R.id.group,startFrag,"");
ft.addtoBackStack("startFrag");
ft.commit();
enter code here
// add other 4 fragments here
when you want to go startFrag on click of some button you can try below code.
fm.popBackStack("startFrag",0);
//where startFrag is the tag which you specify when you called
//addtoBackStack("startFrag")
Upvotes: 2
Reputation: 399
try this one
mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Upvotes: 3
Reputation: 76
You could try this
FragmentManager fm = getFragmentManager();
int count = fm.getBackStackEntryCount();
for(int i = 0; i < count; ++i) {
fm.popBackStack();
}
Upvotes: 3