fragment/src/androidTest/java/androidx/fragment/app/FragmentReorderingTest.java
@Test
    public void startWithPop() throws Throwable {
        // Start with a single fragment on the back stack
        final CountCallsFragment fragment1 = new CountCallsFragment();
        mFM.beginTransaction()
                .add(R.id.fragmentContainer, fragment1)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();

        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer, fragment1);

        // Now pop and add
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFM.popBackStack();
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment1)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.executePendingTransactions();
            }
        });
        FragmentTestUtil.assertChildren(mContainer, fragment1);
        assertEquals(1, fragment1.onCreateViewCount);

        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer);
        assertEquals(1, fragment1.onCreateViewCount);
    }
// the same view back again.
the same view back again.
the same view back again .
@Test
    public void startWithPop() throws Throwable {
        final CountCallsFragment fragment1 = new CountCallsFragment();
        mFM.beginTransaction()
                .add(R.id.fragmentContainer, fragment1)
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer, fragment1);
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                mFM.popBackStack();
                mFM.beginTransaction()
                        .add(R.id.fragmentContainer, fragment1)
                        .addToBackStack(null)
                        .setReorderingAllowed(true)
                        .commit();
                mFM.executePendingTransactions();
            }
        });
        FragmentTestUtil.assertChildren(mContainer, fragment1);
        assertEquals(1, fragment1.onCreateViewCount);
        FragmentTestUtil.popBackStackImmediate(mActivityRule);
        FragmentTestUtil.assertChildren(mContainer);
        assertEquals(1, fragment1.onCreateViewCount);
    }
@ Test public void startWithPop ( ) throws Throwable { final CountCallsFragment fragment1 = new CountCallsFragment ( ) ; mFM . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; FragmentTestUtil . assertChildren ( mContainer , fragment1 ) ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { mFM . popBackStack ( ) ; mFM . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; mFM . executePendingTransactions ( ) ; } } ) ; FragmentTestUtil . assertChildren ( mContainer , fragment1 ) ; assertEquals ( 1 , fragment1 . onCreateViewCount ) ; FragmentTestUtil . popBackStackImmediate ( mActivityRule ) ; FragmentTestUtil . assertChildren ( mContainer ) ; assertEquals ( 1 , fragment1 . onCreateViewCount ) ; }
the same view back again.
the same view back again .
// Start with a single fragment on the back stack // Now pop and add