fragment/src/androidTest/java/androidx/fragment/app/PostponedTransitionTest.java
@Test
    public void saveWhilePostponed() throws Throwable {
        final FragmentController fc1 = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc1, null);

        final FragmentManager fm1 = fc1.getSupportFragmentManager();

        PostponedFragment1 fragment1 = new PostponedFragment1();
        fm1.beginTransaction()
                .add(R.id.fragmentContainer, fragment1, "1")
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);

        Pair<Parcelable, FragmentManagerNonConfig> state =
                FragmentTestUtil.destroy(mActivityRule, fc1);

        final FragmentController fc2 = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc2, state);

        final FragmentManager fm2 = fc2.getSupportFragmentManager();
        Fragment fragment2 = fm2.findFragmentByTag("1");
        assertNotNull(fragment2);
        assertNotNull(fragment2.getView());
        assertEquals(View.VISIBLE, fragment2.getView().getVisibility());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            assertEquals(1f, fragment2.getView().getAlpha(), 0f);
        }
        assertTrue(fragment2.isResumed());
        assertTrue(fragment2.isAdded());
        assertTrue(fragment2.getView().isAttachedToWindow());

        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                assertTrue(fm2.popBackStackImmediate());

            }
        });

        assertFalse(fragment2.isResumed());
        assertFalse(fragment2.isAdded());
        assertNull(fragment2.getView());
    }
// the state as if it wasn't postponed.
the state as if it wasn't postponed.
the state as if it wasn ' t postponed .
@Test
    public void saveWhilePostponed() throws Throwable {
        final FragmentController fc1 = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc1, null);
        final FragmentManager fm1 = fc1.getSupportFragmentManager();
        PostponedFragment1 fragment1 = new PostponedFragment1();
        fm1.beginTransaction()
                .add(R.id.fragmentContainer, fragment1, "1")
                .addToBackStack(null)
                .setReorderingAllowed(true)
                .commit();
        FragmentTestUtil.waitForExecution(mActivityRule);
        Pair<Parcelable, FragmentManagerNonConfig> state =
                FragmentTestUtil.destroy(mActivityRule, fc1);
        final FragmentController fc2 = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc2, state);
        final FragmentManager fm2 = fc2.getSupportFragmentManager();
        Fragment fragment2 = fm2.findFragmentByTag("1");
        assertNotNull(fragment2);
        assertNotNull(fragment2.getView());
        assertEquals(View.VISIBLE, fragment2.getView().getVisibility());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            assertEquals(1f, fragment2.getView().getAlpha(), 0f);
        }
        assertTrue(fragment2.isResumed());
        assertTrue(fragment2.isAdded());
        assertTrue(fragment2.getView().isAttachedToWindow());
        mInstrumentation.runOnMainSync(new Runnable() {
            @Override
            public void run() {
                assertTrue(fm2.popBackStackImmediate());
            }
        });
        assertFalse(fragment2.isResumed());
        assertFalse(fragment2.isAdded());
        assertNull(fragment2.getView());
    }
@ Test public void saveWhilePostponed ( ) throws Throwable { final FragmentController fc1 = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc1 , null ) ; final FragmentManager fm1 = fc1 . getSupportFragmentManager ( ) ; PostponedFragment1 fragment1 = new PostponedFragment1 ( ) ; fm1 . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 , "1" ) . addToBackStack ( null ) . setReorderingAllowed ( true ) . commit ( ) ; FragmentTestUtil . waitForExecution ( mActivityRule ) ; Pair < Parcelable , FragmentManagerNonConfig > state = FragmentTestUtil . destroy ( mActivityRule , fc1 ) ; final FragmentController fc2 = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc2 , state ) ; final FragmentManager fm2 = fc2 . getSupportFragmentManager ( ) ; Fragment fragment2 = fm2 . findFragmentByTag ( "1" ) ; assertNotNull ( fragment2 ) ; assertNotNull ( fragment2 . getView ( ) ) ; assertEquals ( View . VISIBLE , fragment2 . getView ( ) . getVisibility ( ) ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . HONEYCOMB ) { assertEquals ( 1f , fragment2 . getView ( ) . getAlpha ( ) , 0f ) ; } assertTrue ( fragment2 . isResumed ( ) ) ; assertTrue ( fragment2 . isAdded ( ) ) ; assertTrue ( fragment2 . getView ( ) . isAttachedToWindow ( ) ) ; mInstrumentation . runOnMainSync ( new Runnable ( ) { @ Override public void run ( ) { assertTrue ( fm2 . popBackStackImmediate ( ) ) ; } } ) ; assertFalse ( fragment2 . isResumed ( ) ) ; assertFalse ( fragment2 . isAdded ( ) ) ; assertNull ( fragment2 . getView ( ) ) ; }
the state as if it wasn't postponed.
the state as if it wasn ' t postponed .