fragment/src/androidTest/java/androidx/fragment/app/FragmentReorderingTest.java
@Test
    public void middlePop() throws Throwable {
        final CountCallsFragment fragment1 = new CountCallsFragment();
        final CountCallsFragment fragment2 = new CountCallsFragment();
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment1)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.popBackStack();
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.executePendingTransactions();
            }
        });
        FragmentTestUtil.assertChildren(mContainer, fragment2);
        assertEquals(0, fragment1.onAttachCount);
        assertEquals(1, fragment2.onCreateViewCount);

        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer);
        assertEquals(1, fragment2.onDetachCount);
    }
// Popping the back stack in the middle of other operations doesn't fool it.
Popping the back stack in the middle of other operations doesn't fool it.
Popping the back stack in the middle of other operations doesn ' t fool it .
@Test
    public void middlePop() throws Throwable {
        final CountCallsFragment fragment1 = new CountCallsFragment();
        final CountCallsFragment fragment2 = new CountCallsFragment();
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment1)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.popBackStack();
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment2)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.executePendingTransactions();
            }
        });
        FragmentTestUtil.assertChildren(mContainer, fragment2);
        assertEquals(0, fragment1.onAttachCount);
        assertEquals(1, fragment2.onCreateViewCount);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer);
        assertEquals(1, fragment2.onDetachCount);
    }
@ Test public void middlePop ( ) throws Throwable { final CountCallsFragment fragment1 = new CountCallsFragment ( ) ; final CountCallsFragment fragment2 = new CountCallsFragment ( ) ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { mFM . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; mFM . popBackStack ( ) ; mFM . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment2 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; mFM . executePendingTransactions ( ) ; } } ) ; FragmentTestUtil . assertChildren ( mContainer , fragment2 ) ; assertEquals ( 0 , fragment1 . onAttachCount ) ; assertEquals ( 1 , fragment2 . onCreateViewCount ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; FragmentTestUtil . assertChildren ( mContainer ) ; assertEquals ( 1 , fragment2 . onDetachCount ) ; }
Popping the back stack in the middle of other operations doesn't fool it.
Popping the back stack in the middle of other operations doesn ' t fool it .