fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.java
@Test
    @UiThreadTest
    public void fragmentDestroyedOnFinish() throws Throwable {
        FragmentController fc = startupFragmentController(null);
        FragmentManager fm = fc.getSupportFragmentManager();

        StrictViewFragment fragmentA = StrictViewFragment.create(R.layout.fragment_a);
        StrictViewFragment fragmentB = StrictViewFragment.create(R.layout.fragment_b);
        fm.beginTransaction()
                .add(android.R.id.content, fragmentA)
                .commit();
        fm.executePendingTransactions();
        fm.beginTransaction()
                .replace(android.R.id.content, fragmentB)
                .addToBackStack(null)
                .commit();
        fm.executePendingTransactions();
        shutdownFragmentController(fc);
        assertTrue(fragmentB.mCalledOnDestroy);
        assertTrue(fragmentA.mCalledOnDestroy);
    }
/**
     * This tests that fragments call onDestroy when the activity finishes.
     */
This tests that fragments call onDestroy when the activity finishes.
This tests that fragments call onDestroy when the activity finishes .
@Test
    @UiThreadTest
    public void fragmentDestroyedOnFinish() throws Throwable {
        FragmentController fc = startupFragmentController(null);
        FragmentManager fm = fc.getSupportFragmentManager();
        StrictViewFragment fragmentA = StrictViewFragment.create(R.layout.fragment_a);
        StrictViewFragment fragmentB = StrictViewFragment.create(R.layout.fragment_b);
        fm.beginTransaction()
                .add(android.R.id.content, fragmentA)
                .commit();
        fm.executePendingTransactions();
        fm.beginTransaction()
                .replace(android.R.id.content, fragmentB)
                .addToBackStack(null)
                .commit();
        fm.executePendingTransactions();
        shutdownFragmentController(fc);
        assertTrue(fragmentB.mCalledOnDestroy);
        assertTrue(fragmentA.mCalledOnDestroy);
    }
@ Test @ UiThreadTest public void fragmentDestroyedOnFinish ( ) throws Throwable { FragmentController fc = startupFragmentController ( null ) ; FragmentManager fm = fc . getSupportFragmentManager ( ) ; StrictViewFragment fragmentA = StrictViewFragment . create ( R . layout . fragment_a ) ; StrictViewFragment fragmentB = StrictViewFragment . create ( R . layout . fragment_b ) ; fm . beginTransaction ( ) . add ( android . R . id . content , fragmentA ) . commit ( ) ; fm . executePendingTransactions ( ) ; fm . beginTransaction ( ) . replace ( android . R . id . content , fragmentB ) . addToBackStack ( null ) . commit ( ) ; fm . executePendingTransactions ( ) ; shutdownFragmentController ( fc ) ; assertTrue ( fragmentB . mCalledOnDestroy ) ; assertTrue ( fragmentA . mCalledOnDestroy ) ; }
This tests that fragments call onDestroy when the activity finishes.
This tests that fragments call onDestroy when the activity finishes .