2014-01-27 48 views

回答

5

當您使用FragmentTransaction添加片段時,有addToBackStack選項,如果您不使用它,它將不會在堆棧中。

// it won't add to stack 
getSupportFragmentManager().beginTransaction() 
     .add(R.id.container, new PlaceholderFragment()) 
     .commit(); 

// fragment will be added to stack 
getSupportFragmentManager().beginTransaction() 
    .add(R.id.container, new PlaceholderFragment()) 
    .addToBackStack("placeholder") 
     commit(); 
2

默認情況下,片段不會添加到堆棧中。您需要從您的代碼中刪除對addToStack()的呼叫。