fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.java
@Test
    @UiThreadTest
    public void retainInstanceOneOnCreate() throws Throwable {
        FragmentController fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, null);
        FragmentManager fm = fc.getSupportFragmentManager();

        OnCreateFragment fragment = new OnCreateFragment();

        fm.beginTransaction()
                .add(fragment, "fragment")
                .commit();
        fm.executePendingTransactions();

        fm.beginTransaction()
                .remove(fragment)
                .addToBackStack(null)
                .commit();

        assertTrue(fragment.onCreateCalled);
        fragment.onCreateCalled = false;

        Pair<Parcelable, FragmentManagerNonConfig> savedState =
                FragmentTestUtil.destroy(mActivityRule, fc);

        fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, savedState);
        fm = fc.getSupportFragmentManager();

        fm.popBackStackImmediate();
        assertFalse(fragment.onCreateCalled);
    }
/**
     * A retained instance fragment should go through onCreate() once, even through save and
     * restore.
     */
A retained instance fragment should go through onCreate() once, even through save and
restore.
A retained instance fragment should go through onCreate () once even through save and restore .
@Test
    @UiThreadTest
    public void retainInstanceOneOnCreate() throws Throwable {
        FragmentController fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, null);
        FragmentManager fm = fc.getSupportFragmentManager();
        OnCreateFragment fragment = new OnCreateFragment();
        fm.beginTransaction()
                .add(fragment, "fragment")
                .commit();
        fm.executePendingTransactions();
        fm.beginTransaction()
                .remove(fragment)
                .addToBackStack(null)
                .commit();
        assertTrue(fragment.onCreateCalled);
        fragment.onCreateCalled = false;
        Pair<Parcelable, FragmentManagerNonConfig> savedState =
                FragmentTestUtil.destroy(mActivityRule, fc);
        fc = FragmentTestUtil.createController(mActivityRule);
        FragmentTestUtil.resume(mActivityRule, fc, savedState);
        fm = fc.getSupportFragmentManager();
        fm.popBackStackImmediate();
        assertFalse(fragment.onCreateCalled);
    }
@ Test @ UiThreadTest public void retainInstanceOneOnCreate ( ) throws Throwable { FragmentController fc = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc , null ) ; FragmentManager fm = fc . getSupportFragmentManager ( ) ; OnCreateFragment fragment = new OnCreateFragment ( ) ; fm . beginTransaction ( ) . add ( fragment , "fragment" ) . commit ( ) ; fm . executePendingTransactions ( ) ; fm . beginTransaction ( ) . remove ( fragment ) . addToBackStack ( null ) . commit ( ) ; assertTrue ( fragment . onCreateCalled ) ; fragment . onCreateCalled = false ; Pair < Parcelable , FragmentManagerNonConfig > savedState = FragmentTestUtil . destroy ( mActivityRule , fc ) ; fc = FragmentTestUtil . createController ( mActivityRule ) ; FragmentTestUtil . resume ( mActivityRule , fc , savedState ) ; fm = fc . getSupportFragmentManager ( ) ; fm . popBackStackImmediate ( ) ; assertFalse ( fragment . onCreateCalled ) ; }
A retained instance fragment should go through onCreate() once, even through save and
 restore.
A retained instance fragment should go through onCreate () once even through save and restore .