我有一個片段,例如A→B→C。當我在片段C中,並按下後退按鈕時,我需要得到片段A也就是說,片段B不需要添加到backStack。這是實現片段之間轉換的代碼。從片段C返回片段A後退按鈕
FragmentManager fragmentManager = this.getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
Fragment fragment = fragmentManager.findFragmentByTag(tag);
fragment.getArguments().putAll(args);
transaction.replace(idContainer, fragment, tag);
transaction.addToBackStack(null);
transaction.commit();
在片段C的開口,我不使用transaction.addToBackStack(空);
現在我有以下問題。從片段С我單擊後退按鈕並進入片段A,但兩層碎片相互疊加。
在堆棧中添加所有的片段,然後迭代循環,直到第一個片段 – Bhavnik
您使用viewpager? –
也許你想檢查[這個問題](http://stackoverflow.com/questions/18634207/difference-between-add-replace-and-addtobackstack) –