3

有一个带有 5 个片段的 Activity(向导)。

StartFrag  -(start)-> Frag1 -(next)-> Frag2 -(next)-> SubmitFrag
-(submit)-> SuccessFrag.

在 Success 片段上点击 SubmitMore 按钮后,我想从后台删除 Frag1、Frag2 和 SubmitFrag 并返回 StartFrag。怎么做?

4

3 回答 3

3

你可以试试这个

FragmentManager fm = getFragmentManager(); 
int count = fm.getBackStackEntryCount();
for(int i = 0; i < count; ++i) {    
fm.popBackStack();
}
于 2015-06-09T09:58:22.920 回答
3

试试这个

   mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); 
于 2015-06-09T10:07:15.280 回答
2

你可以试试这个

 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")
于 2015-06-09T10:31:07.350 回答