In my simple layout, there is only a fragment:
<FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
First add the 1st snippet to this placeholder:
fragmentTransaction.add(R.id.fragment_placeholder, firstFragment, "first");
I have a 2nd snippet that replaces the above snippet and pushes it back onto the stack :
FragmentManager fragMgr = getSupportFragmentManager();
FragmentTransaction fragTrans = fragMgr.beginTransaction();
Fragment secondFragment = initSecondFragment();
fragTrans.replace(R.id.fragment_placeholder, secondFragment, "second");
fragTrans.addToBackStack(null);
fragTrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragTrans.commit();
Later I have fragments that replace the previous fragment, but DO NOT fit in the backstack .
It seems that those fragments that were not placed in the backstack will always be displayed on the screen, pressing the "Back" button will not have an effect for them.
, , backstack , , ?