hhs
hhs

Reputation: 714

How to remove Fragments from backstack

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

Answers (3)

Manish DEWAN
Manish DEWAN

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

SAM
SAM

Reputation: 399

try this one

   mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 

Upvotes: 3

funkomatic
funkomatic

Reputation: 76

You could try this

FragmentManager fm = getFragmentManager(); 
int count = fm.getBackStackEntryCount();
for(int i = 0; i < count; ++i) {    
fm.popBackStack();
}

Upvotes: 3

Related Questions