3

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?

G.L.P
  • 7,119
  • 5
  • 25
  • 41
hhs
  • 716
  • 1
  • 6
  • 22

3 Answers3

3

You could try this

FragmentManager fm = getFragmentManager(); 
int count = fm.getBackStackEntryCount();
for(int i = 0; i < count; ++i) {    
fm.popBackStack();
}
funkomatic
  • 76
  • 6
3

try this one

   mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 
SAM
  • 399
  • 2
  • 9
2

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")
Limon Monte
  • 52,539
  • 45
  • 182
  • 213