fragment/src/androidTest/java/androidx/fragment/app/NestedInflatedFragmentTest.java
@Test
    @UiThreadTest
    public void nestedSetUserVisibleHint() throws Throwable {
        FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();

        // Add a UserVisibleHintParentFragment
        UserVisibleHintParentFragment fragment = new UserVisibleHintParentFragment();
        fm.beginTransaction().add(android.R.id.content, fragment).commit();
        fm.executePendingTransactions();

        fragment.setUserVisibleHint(false);

        Fragment.SavedState state = fm.saveFragmentInstanceState(fragment);
        fm.beginTransaction().remove(fragment).commit();
        fm.executePendingTransactions();

        fragment = new UserVisibleHintParentFragment();
        fragment.setInitialSavedState(state);
        fragment.setUserVisibleHint(true);

        fm.beginTransaction().add(android.R.id.content, fragment).commit();
        fm.executePendingTransactions();
    }
/**
     * This mimics the behavior of FragmentStatePagerAdapter jumping between pages
     */
This mimics the behavior of FragmentStatePagerAdapter jumping between pages
This mimics the behavior of FragmentStatePagerAdapter jumping between pages
@Test
    @UiThreadTest
    public void nestedSetUserVisibleHint() throws Throwable {
        FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        UserVisibleHintParentFragment fragment = new UserVisibleHintParentFragment();
        fm.beginTransaction().add(android.R.id.content, fragment).commit();
        fm.executePendingTransactions();
        fragment.setUserVisibleHint(false);
        Fragment.SavedState state = fm.saveFragmentInstanceState(fragment);
        fm.beginTransaction().remove(fragment).commit();
        fm.executePendingTransactions();
        fragment = new UserVisibleHintParentFragment();
        fragment.setInitialSavedState(state);
        fragment.setUserVisibleHint(true);
        fm.beginTransaction().add(android.R.id.content, fragment).commit();
        fm.executePendingTransactions();
    }
@ Test @ UiThreadTest public void nestedSetUserVisibleHint ( ) throws Throwable { FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; UserVisibleHintParentFragment fragment = new UserVisibleHintParentFragment ( ) ; fm . beginTransaction ( ) . add ( android . R . id . content , fragment ) . commit ( ) ; fm . executePendingTransactions ( ) ; fragment . setUserVisibleHint ( false ) ; Fragment . SavedState state = fm . saveFragmentInstanceState ( fragment ) ; fm . beginTransaction ( ) . remove ( fragment ) . commit ( ) ; fm . executePendingTransactions ( ) ; fragment = new UserVisibleHintParentFragment ( ) ; fragment . setInitialSavedState ( state ) ; fragment . setUserVisibleHint ( true ) ; fm . beginTransaction ( ) . add ( android . R . id . content , fragment ) . commit ( ) ; fm . executePendingTransactions ( ) ; }
This mimics the behavior of FragmentStatePagerAdapter jumping between pages
This mimics the behavior of FragmentStatePagerAdapter jumping between pages
// Add a UserVisibleHintParentFragment