Google is committed to advancing racial equity for Black communities. See how.

Fragment

Segment your app into multiple, independent screens that are hosted within an Activity.

Latest Update Current Stable Release Next Release Candidate Beta Release Alpha Release August 19, 2020 1.2.5 - - 1.3.0-alpha08

Declaring dependencies

To add a dependency on Fragment, you must add the Google Maven repository to your project. Read Google's Maven repository for more information.

Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

dependencies { def fragment_version = "1.2.5" // Java language implementation implementation "androidx.fragment:fragment:$fragment_version" // Kotlin implementation "androidx.fragment:fragment-ktx:$fragment_version" // Testing Fragments in Isolation debugImplementation "androidx.fragment:fragment-testing:$fragment_version" }

For more information about dependencies, see Add build dependencies.

Feedback

Your feedback helps make Jetpack better. Let us know if you discover new issues or have ideas for improving this library. Please take a look at the existing issues in this library before you create a new one. You can add your vote to an existing issue by clicking the star button.

Create a new issue

See the Issue Tracker documentation for more information.

Version 1.3.0

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.3.0-alpha08

August 19, 2020

androidx.fragment:fragment:1.3.0-alpha08 , androidx.fragment:fragment-ktx:1.3.0-alpha08 , and androidx.fragment:fragment-testing:1.3.0-alpha08 are released. Version 1.3.0-alpha08 contains these commits.

New State Manager

This release includes a major refactoring of the internal state management of FragmentManager which affects the dispatch of lifecycle methods, animations and transitions, and how postponed transactions are handled. This is enabled by default. See the Fragments: Rebuilding the Internals blog post for more details. (b/139536619, b/147749580)

An experimental API in FragmentManager.enableNewStateManager(boolean) can be used to control whether FragmentManager uses the new state manager. (I7b6ee)

The following issues are fixed only when using the new state manager:

The previous fragment of a replace operation is now correctly stopped before the new fragment is started. (b/161654580)

operation is now correctly stopped before the new fragment is started. (b/161654580) Fragments now prevent multiple competing animations on the same fragments, avoiding cases where an Animation would override all Transition effects or an Animator and a Transition on an individual fragment would both run. (b/149569323)

would override all effects or an and a on an individual fragment would both run. (b/149569323) The enterTransition and exitTranstion of all fragments entering and exiting are now ran rather than only the last entering fragment and the first exiting fragment. (b/149344150)

and of fragments entering and exiting are now ran rather than only the last entering fragment and the first exiting fragment. (b/149344150) Postponed fragments no longer get stuck at the CREATED state but instead move to STARTED with other fragments. (b/129035555)

state but instead move to with other fragments. (b/129035555) Fixed an issue where FragmentManager would execute operations out of order when mixing a postponed re-ordered transaction and a non-reordered transaction. (b/147297731)

would execute operations out of order when mixing a postponed re-ordered transaction and a non-reordered transaction. (b/147297731) Popping multiple fragments simultaneously will no longer result in intermediate fragments being temporarily visible when postponing fragments. (b/37140383)

FragmentManager now returns the correct fragments when calling findFragmentById() or findFragmentByTag() from within the onAttachFragment() callback. (b/153082833)

now returns the correct fragments when calling or from within the callback. (b/153082833) Fragments no longer call onCreateView() on fragments being destroyed when the fragment replacing them is postponed. (b/143915710)

on fragments being destroyed when the fragment replacing them is postponed. (b/143915710) The error message when attempting to combine framework Transition and AndroidX Transition instances now mentions the fragment with the invalid transition. (b/155574969)

Behavior Changes

You can now call launch() on an ActivityResultLauncher in the onCreate() lifecycle method of a fragment. (b/161464278)

on an in the lifecycle method of a fragment. (b/161464278) Calling registerForActivityResult() after onCreate() now throws an exception indicating that this is not allowed rather than silently failing to deliver results after a configuration change. (b/162255449)

after now throws an exception indicating that this is not allowed rather than silently failing to deliver results after a configuration change. (b/162255449) FragmentActivity now uses the OnContextAvailableListener API introduced in Activity 1.2.0-alpha08 to restore the state of the FragmentManager . Any listeners added to subclasses of FragmentActivity will run after this listener. (I513da)

Bug Fixes

ActivityOptions passed through when using startIntentSenderForResult() are now respected. (b/162247961)

Known Issue

When using the new state manager, directly setting the visibility of the fragment’s root view after onViewCreated() and before onResume() results in the visibility you set being overridden by FragmentManager , who controls the visibility of the root view. As a workaround, you should always use the hide() and show() operations to change the visibility of your fragment. (b/164481490)

Version 1.3.0-alpha07

July 22, 2020

androidx.fragment:fragment:1.3.0-alpha07 , androidx.fragment:fragment-ktx:1.3.0-alpha07 , and androidx.fragment:fragment-testing:1.3.0-alpha07 are released. Version 1.3.0-alpha07 contains these commits.

New Features

FragmentScenario now supports setting an initial Lifecycle state of CREATED , STARTED , or RESUMED rather than always moving the Fragment to the RESUMED state. (b/159662750)

now supports setting an initial Lifecycle state of , , or rather than always moving the Fragment to the state. (b/159662750) Added an alternative to the FragmentScenario API of onFragment in the form of the Kotlin reified extension method withFragment that allows you to return a value. Notably, it rethrows exceptions raised in the given block. (b/158697631)

Behavior Changes

FragmentScenario now uses setMaxLifecycle() to implement moveToState() , ensuring consistent behavior on all API levels and decoupling the Fragment’s state from the underlying Activity. (b/156527405)

now uses to implement , ensuring consistent behavior on all API levels and decoupling the Fragment’s state from the underlying Activity. (b/156527405) The SavedStateRegistryOwner returned by ViewTreeSavedStateRegistryOwner is now tied to the fragment view’s Lifecycle. This ensures that it has its state saved and restore at the same time as the fragment’s view. (b/158503763)

Bug Fixes

Fragments now wait for the fragment’s view to be attached before calling ViewCompat.requestApplyInsets() , avoiding cases where the inset request was being dropped. (b/158095749)

, avoiding cases where the inset request was being dropped. (b/158095749) Calling clearFragmentResultListener now properly clears the lifecycle observer. (b/159274993)

Version 1.3.0-alpha06

June 10, 2020

androidx.fragment:fragment:1.3.0-alpha06 , androidx.fragment:fragment-ktx:1.3.0-alpha06 , and androidx.fragment:fragment-testing:1.3.0-alpha06 are released. Version 1.3.0-alpha06 contains these commits.

New Features

The onAttachFragment() callback on FragmentActivity and Fragment have been deprecated. A new FragmentOnAttachListener has been added to provide a more flexible alternative, allowing delegation of onAttachFragment() to separate, testable listeners and support for adding a listener to FragmentManagers other than your direct child FragmentManager. (I06d3d)

Bug Fixes

Parent fragments now have their view state restored before their child fragments, fixing a visual ordering issue after a configuration change when a DialogFragment would show another DialogFragment as a child fragment. (b/157195715)

would show another as a child fragment. (b/157195715) Fixed an issue where the UseRequireInsteadOfGet Lint check would not handle chained usages of the ?. and !! operators correctly. (b/157677616)

Version 1.3.0-alpha05

May 20, 2020

androidx.fragment:fragment:1.3.0-alpha05 , androidx.fragment:fragment-ktx:1.3.0-alpha05 , and androidx.fragment:fragment-testing:1.3.0-alpha05 are released. Version 1.3.0-alpha05 contains these commits.

New Features

Added support for ViewTreeViewModelStoreOwner from Lifecycle 2.3.0-alpha03 , and ViewTreeSavedStateRegistryOwner from SavedState 1.1.0-alpha01 when using a View within a Fragment . (aosp/1297993, aosp/1300264)

API Changes

The setFragmentResult() and setFragmentResultListener() APIs now take a non-null Bundle and FragmentResultListener , respectively. To explicitly clear a previously set result or listener, use the new clearFragmentResult() and clearFragmentResultListener() methods. (b/155416778)

and APIs now take a non-null and , respectively. To explicitly clear a previously set result or listener, use the new and methods. (b/155416778) The setFragmentResultListener() Kotlin extensions that take a lambda are now marked as inline . (b/155323404)

Behavior Changes

The previously deprecated startActivityForResult() , startIntentSenderForResult() , and requestPermissions on Fragment now internally use ActivityResultRegistry , thus removing the restriction on using only the lower bits (below 0xFFFF ) for your request codes when using those APIs. (b/155518741)

Documentation Updates

Expanded the documentation on the Fragment(@LayoutRes int) and DialogFragment(@LayoutRes int) constructors to clarify that they should be called from your subclasses’ no argument constructor when using the default FragmentFactory . (b/153042497)

Version 1.3.0-alpha04

April 29, 2020

androidx.fragment:fragment:1.3.0-alpha04 , androidx.fragment:fragment-ktx:1.3.0-alpha04 , and androidx.fragment:fragment-testing:1.3.0-alpha04 are released. Version 1.3.0-alpha04 contains these commits.

New Features

Added support for passing results between two Fragments via new APIs on FragmentManager . This works for hierarchy fragments (parent/child), DialogFragments, and fragments in Navigation and ensures that results are only sent to your Fragment while it is at least STARTED . (b/149787344)

API Changes

The target fragment APIs have been deprecated. To pass data between fragments the new Fragment Result APIs should be used instead. (b/149787344)

The startActivityForResult() / onActivityResult() and requestPermissions() / onRequestPermissionsResult() APIs on Fragment have been deprecated. Please use the Activity Result APIs. (aosp/1290887)

/ and / APIs on Fragment have been deprecated. Please use the Activity Result APIs. (aosp/1290887) Breaking change from Activity 1.2.0-alpha04 : the prepareCall() method has been renamed to registerForActivityResult() . (aosp/1278717)

Bug Fixes

The fragment’s getViewLifecycleOwner() is now stopped before onSaveInstanceState() is called, mirroring the behavior of the fragment’s lifecycle. (b/154645875)

is now stopped before is called, mirroring the behavior of the fragment’s lifecycle. (b/154645875) Calling setMenuVisibility(false) on a fragment now correctly changes the visibility of menus provided by its child fragments. (b/153593580)

on a fragment now correctly changes the visibility of menus provided by its child fragments. (b/153593580) Fixed an illegalStateException when adding a fragment to a DialogFragment ’s view hierarchy with FragmentContainerView . (b/154366601)

when adding a fragment to a ’s view hierarchy with . (b/154366601) The getDefaultViewModelProviderFactory() method on fragments no longer crashes when hosting your fragments outside of an activity. (b/153762914)

Version 1.3.0-alpha03

April 1, 2020

androidx.fragment:fragment:1.3.0-alpha03 , androidx.fragment:fragment-ktx:1.3.0-alpha03 , and androidx.fragment:fragment-testing:1.3.0-alpha03 are released. Version 1.3.0-alpha03 contains these commits.

API Changes

The prepareCall methods on Fragment are now final . (b/152439361)

Bug Fixes

Fixed a regression introduced in Fragment 1.3.0-alpha02 when using BottomSheetDialogFragment . (b/151652127, aosp/1263328, aosp/1265163)

when using . (b/151652127, aosp/1263328, aosp/1265163) Fixed a crash when using prepareCall from a fragment after a configuration change. (b/152137004)

from a fragment after a configuration change. (b/152137004) Fixed an issue where shared element and exit transitions are ignored when using setTargetFragment() . (b/152023196)

. (b/152023196) From Fragment 1.2.4 : Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. (b/151605338)

: Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. (b/151605338) From Fragment 1.2.4 : Disabled the FragmentLiveDataObserve Lint rule on DialogFragment classes as their lifecycle and view lifecycle are always in sync, making it safe to use either this or viewLifecycleOwner when calling observe . (b/151765086)

Dependency Changes

Fragments depend on Activity 1.2.0-alpha03 , which had significant improvements to the Activity Result API introduced in Activity 1.2.0-alpha02 .

Version 1.3.0-alpha02

March 18, 2020

androidx.fragment:fragment:1.3.0-alpha02 , androidx.fragment:fragment-ktx:1.3.0-alpha02 , and androidx.fragment:fragment-testing:1.3.0-alpha02 are released. Version 1.3.0-alpha02 contains these commits.

New Features

Added support for the ActivityResultRegistry API introduced in Activity 1.2.0-alpha02 to handle the startActivityForResult() + onActivityResult() as well as requestPermissions() + onRequestPermissionsResult() flows without overriding methods in your Fragment in addition to providing hooks for testing these flows. See the updated Getting a Result from an Activity. (b/125158199)

API Changes

DialogFragment now provides a constructor that takes a @LayoutRes that indicates the layout that onCreateView() should inflate by default. (b/150327080)

now provides a constructor that takes a that indicates the layout that should inflate by default. (b/150327080) The onActivityCreated() method is now deprecated. Code touching the fragment's view should be done in onViewCreated() (which is called immediately before onActivityCreated() ) and other initialization code should be in onCreate() . To receive a callback specifically when the activity's onCreate() is complete, a LifeCycleObserver should be registered on the activity's Lifecycle in onAttach() , and removed once the onCreate() callback is received. (b/144309266)

Bug Fixes

From Fragment 1.2.3 : Fixed a bug in DialogFragment that caused a StackOverflowError when calling getLayoutInflater() from within onCreateDialog() . (b/117894767, aosp/1258664)

: Fixed a bug in that caused a when calling from within . (b/117894767, aosp/1258664) From Fragment 1.2.3 : Reduced the scope of Fragment’s included ProGuard rules to ensure that unused Fragment classes can be stripped. (b/149665169)

: Reduced the scope of Fragment’s included ProGuard rules to ensure that unused Fragment classes can be stripped. (b/149665169) From Fragment 1.2.3 : Fixed false positives in the UseRequireInsteadOfGet Lint check when using a local variable name that shadowed the Kotlin property name. (b/149891163)

: Fixed false positives in the Lint check when using a local variable name that shadowed the Kotlin property name. (b/149891163) From Fragment 1.2.3 : FragmentContainerView no longer throws an UnsupportedOperationException for using the incorrect constructor in layout preview. (b/149707833)

Known Issues

BottomSheetDialogFragment no longer properly positions its dialog on the screen. (b/151652127)

Version 1.3.0-alpha01

March 4, 2020

androidx.fragment:fragment:1.3.0-alpha01 , androidx.fragment:fragment-ktx:1.3.0-alpha01 , and androidx.fragment:fragment-testing:1.3.0-alpha01 are released. Version 1.3.0-alpha01 contains these commits.

New Features

Added support for the ViewTreeLifecycleOwner.get(View) API added in Lifecycle 2.3.0-alpha01 such that it will return the Fragment’s viewLifecycleOwner as the LifecycleOwner for any Views returned by onCreateView() . (aosp/1182955)

API Changes

The setRetainInstance() method on Fragments has been deprecated. With the introduction of ViewModels, developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate, avoiding a common source of leaks while maintaining the useful properties of a single creation and destruction of the retained state (namely, the constructor of the ViewModel and the onCleared() callback it receives). (b/143911815)

method on Fragments has been deprecated. With the introduction of ViewModels, developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate, avoiding a common source of leaks while maintaining the useful properties of a single creation and destruction of the retained state (namely, the constructor of the and the callback it receives). (b/143911815) With the release of ViewPager2 1.0.0 , the FragmentPagerAdapter and FragmentStatePagerAdapter classes for interacting with ViewPager have been deprecated. See Migrate from ViewPager to ViewPager2. (b/145132715)

Bug Fixes

Fragment ProGuard rules now correctly only keep the default constructors Fragment classes that are used rather than for all Fragment instances, fixing a regression introduced in Fragment 1.2.1 . (b/149665169

classes that are used rather than for all instances, fixing a regression introduced in Fragment . (b/149665169 The require___() Lint rules added in Fragment 1.2.2 no longer false positive on local variables that share the same name as the shadowed Kotlin property names (i.e., view ). (b/149891163)

Lint rules added in Fragment no longer false positive on local variables that share the same name as the shadowed Kotlin property names (i.e., ). (b/149891163) FragmentContainerView no longer throws an UnsupportedOperationException when using the layout preview in Android Studio. (b/149707833)

no longer throws an when using the layout preview in Android Studio. (b/149707833) Fixed an issue where retained fragments that were added after the state is saved would not be continually recreated and then destroyed after each configuration change. (b/145832397)

Version 1.2.5

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.5

June 10, 2020

androidx.fragment:fragment:1.2.5 , androidx.fragment:fragment-ktx:1.2.5 , and androidx.fragment:fragment-testing:1.2.5 are released. Version 1.2.5 contains these commits.

Bug Fixes

The fragment’s getViewLifecycleOwner() is now stopped before onSaveInstanceState() is called, mirroring the behavior of the fragment’s lifecycle. This was previously released in Fragment 1.3.0-alpha04 . (b/154645875)

is now stopped before is called, mirroring the behavior of the fragment’s lifecycle. This was previously released in Fragment . (b/154645875) Calling setMenuVisibility(false) on a fragment now correctly changes the visibility of menus provided by its child fragments. This was previously released in Fragment 1.3.0-alpha04 . (b/153593580)

Version 1.2.4

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.4

April 1, 2020

androidx.fragment:fragment:1.2.4 , androidx.fragment:fragment-ktx:1.2.4 , and androidx.fragment:fragment-testing:1.2.4 are released. Version 1.2.4 contains these commits.

Bug Fixes

Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. (b/151605338)

Disabled the FragmentLiveDataObserve Lint rule on DialogFragment classes as their lifecycle and view lifecycle are always in sync, making it safe to use either this or viewLifecycleOwner when calling observe . (b/151765086)

Version 1.2.3

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.3

March 18, 2020

androidx.fragment:fragment:1.2.3 , androidx.fragment:fragment-ktx:1.2.3 , and androidx.fragment:fragment-testing:1.2.3 are released. Version 1.2.3 contains these commits.

Bug Fixes

Fixed a bug in DialogFragment that caused a StackOverflowError when calling getLayoutInflater() from within onCreateDialog() . (b/117894767, aosp/1258665)

that caused a when calling from within . (b/117894767, aosp/1258665) Reduced the scope of Fragment’s included ProGuard rules to ensure that unused Fragment classes can be stripped. (b/149665169)

Fixed false positives in the UseRequireInsteadOfGet Lint check when using a local variable name that shadowed the Kotlin property name. (b/149891163)

Lint check when using a local variable name that shadowed the Kotlin property name. (b/149891163) FragmentContainerView no longer throws an UnsupportedOperationException for using the incorrect constructor in layout preview. (b/149707833)

Version 1.2.2

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.2

February 19, 2020

androidx.fragment:fragment:1.2.2 , androidx.fragment:fragment-ktx:1.2.2 , and androidx.fragment:fragment-testing:1.2.2 are released. Version 1.2.2 contains these commits.

New Lint checks

Lint suggests using the viewLifecycleOwner as the LifecycleOwner to calls into OnBackPressedDispatcher in onCreateView() , onViewCreated() , and onActivityCreated() . (b/142117657)

as the to calls into in , , and . (b/142117657) Added a new Lint check that confirms that you are using the correct debugImplementation when using the fragment-testing artifact. (b/141500106)

when using the artifact. (b/141500106) Fragments now suggest using the associated require___() methods for more descriptive error messages instead of checkNotNull(get___()) , requireNonNull(get___()) , or get___()!! for all of the Fragment APIs that include both a get and require equivalent. (aosp/1202883)

Bug Fixes

Fixed the Fragment ProGuard files to avoid R8 warnings (b/148963981)

Improved the existing Lint check suggesting using viewLifecycleOwner when using observe to also handle the livedata-ktx extension method version of observe . (b/148996309)

when using to also handle the extension method version of . (b/148996309) Fixed the formatting for many of the Lint checks (aosp/1157012)

External contributions

Thanks to Zac Sweers for contributing the require___() Lint checks on behalf of Slack! (aosp/1202883)

Version 1.2.1

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.1

February 5, 2020

androidx.fragment:fragment:1.2.1 , androidx.fragment:fragment-ktx:1.2.1 , and androidx.fragment:fragment-testing:1.2.1 are released. Version 1.2.1 contains these commits.

Bug fixes

Fragments added via the add and replace methods that take a Class instance (or the Kotlin reified versions) now have their default constructor kept by ProGuard. (b/148181315)

and methods that take a instance (or the Kotlin reified versions) now have their default constructor kept by ProGuard. (b/148181315) FragmentStatePagerAdapter and FragmentPagerAdapter no longer catch exceptions thrown by FragmentManager when running finishUpdate() . (aosp/1208711)

and no longer catch exceptions thrown by when running . (aosp/1208711) Fixed an issue where FragmentManager.findFragment() did not work with fragments added via the <fragment> tag. (b/147784323)

did not work with fragments added via the tag. (b/147784323) Fragments inflated using the <fragment> tag now always receive a call to onInflate() before onCreate() when in the layout. (aosp/1215856)

tag now always receive a call to before when in the layout. (aosp/1215856) Calling toString() on a FragmentManager instance no longer throws a NullPointerException when the Activity is already destroyed. (b/148189412)

Dependency changes

Fragments 1.2.1 now depends on Lifecycle ViewModel SavedState 2.2.0 .

Version 1.2.0

Note: fragment-ktx , fragment-testing ) target Java 8 programming language bytecode. Please read The Kotlin dependant libraries of this version () target Java 8 programming language bytecode. Please read Use Java 8 language features to learn how to use it in your project.

Version 1.2.0

January 22, 2020

androidx.fragment:fragment:1.2.0 , androidx.fragment:fragment-ktx:1.2.0 , and androidx.fragment:fragment-testing:1.2.0 are released. Version 1.2.0 contains these commits.

Important changes since 1.1.0

FragmentContainerView : The FragmentContainerView is the strongly recommended container for dynamically added Fragments, replacing usage of FrameLayout or other layouts. It also supports the same class , android:name , and optional android:tag as the <fragment> tag, but uses a normal FragmentTransaction to add this initial fragment, instead of the custom code path used by <fragment> .

: The is the strongly recommended container for dynamically added Fragments, replacing usage of or other layouts. It also supports the same , , and optional as the tag, but uses a normal to add this initial fragment, instead of the custom code path used by . onDestroyView() timing : Fragments now wait for exit animations, exit framework transitions, and exit AndroidX transitions (when using Transition 1.3.0 ) to complete before calling onDestroyView() .

: Fragments now wait for exit animations, exit framework transitions, and exit AndroidX transitions (when using Transition ) to complete before calling . Class based add() and replace() : Added new overloads of add() and replace() on FragmentTransaction that take a Class<? extends Fragment> and optional Bundle of arguments. These methods use your FragmentFactory to construct an instance of the Fragment to add. Kotlin extensions that use reified types (i.e, fragmentTransaction.replace<YourFragment>(R.id.container) ) have also been added to fragment-ktx .

: Added new overloads of and on that take a and optional of arguments. These methods use your to construct an instance of the Fragment to add. Kotlin extensions that use reified types (i.e, ) have also been added to . Lifecycle ViewModel SavedState Integration : SavedStateViewModelFactory is now the default factory used when using by viewModels() , by activityViewModels() , the ViewModelProvider constructor, or ViewModelProviders.of() with a Fragment.

: is now the default factory used when using , , the constructor, or with a Fragment. New Lint checks : Added a new Lint check that ensures you are using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() .

: Added a new Lint check that ensures you are using when observing from , , or . getFragmentManager() deprecation : The getFragmentManager() and requireFragmentManager() methods on Fragment have been deprecated and replaced with a single getParentFragmentManager() method, which returns the non-null FragmentManager the Fragment is added to (you can use isAdded() to determine if it is safe to call).

: The and methods on Fragment have been deprecated and replaced with a single method, which returns the non-null the Fragment is added to (you can use to determine if it is safe to call). FragmentManager.enableDebugLogging() deprecation: The static FragmentManager.enableDebugLogging method has been deprecated. FragmentManager now respects Log.isLoggable() for the tag FragmentManager , allowing you to enable either DEBUG or VERBOSE logging without re-compiling your app.

Known Issues

Fragments referenced only via the class or android:name attribute on a FragmentContainerView are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. (b/142601969)

or attribute on a are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. (b/142601969) When adding a NavHostFragment using class or android:name in XML with FragmentContainerView , you cannot use findNavController() in onCreate() of your Activity. (b/142847973)

Version 1.2.0-rc05

January 8, 2020

androidx.fragment:fragment:1.2.0-rc05 , androidx.fragment:fragment-ktx:1.2.0-rc05 , and androidx.fragment:fragment-testing:1.2.0-rc05 are released. Version 1.2.0-rc05 contains these commits.

Bug fixes

Fixed a regression in Fragment 1.2.0-rc04 when using the <fragment> tag which caused onViewCreated() to be called incorrectly during activity destruction. (b/146290333)

when using the tag which caused to be called incorrectly during activity destruction. (b/146290333) Fragments added with the <fragment> tag now properly have their non-config cleared even when they are only sometimes in the layout (i.e., only in your landscape layout). As a consequence, these Fragments are now correctly moved to CREATED even when not in your layout instead of being instantiated but never moving through any lifecycle methods. (b/145769287)

Version 1.2.0-rc04

December 18, 2019

androidx.fragment:fragment:1.2.0-rc04 , androidx.fragment:fragment-ktx:1.2.0-rc04 , and androidx.fragment:fragment-testing:1.2.0-rc04 are released. Version 1.2.0-rc04 contains these commits.

Bug fixes

Adjusted the animations for TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , and TRANSIT_FRAGMENT_FADE to avoid visual issues. (b/145468417)

Version 1.2.0-rc03

December 4, 2019

androidx.fragment:fragment:1.2.0-rc03 , androidx.fragment:fragment-ktx:1.2.0-rc03 , and androidx.fragment:fragment-testing:1.2.0-rc03 are released. Version 1.2.0-rc03 contains these commits.

Bug fixes

Fixed an unintentional behavior change where Fragments who have been removed are still returned by findFragmentById() / findFragmentByTag() while their exit animations/transitions run. (b/143982969, aosp/1167585)

/ while their exit animations/transitions run. (b/143982969, aosp/1167585) Child fragments are now correctly stopped before their parents when the containing activity calls onSaveInstanceState() . (b/144380645)

. (b/144380645) Fixed an issue where Views were incorrectly marked INVISIBLE after popping a hidden Fragment. (b/70793925)

after popping a hidden Fragment. (b/70793925) Fragment shared element transitions now handle Views that have been rotated, scaled, etc. (b/142835261)

Documentation Updates

Clarified the deprecation documentation around setUserVisibleHint() . (b/143897055)

. (b/143897055) Improved the documentation on setFragmentFactory() and getFragmentFactory() to better indicate that setting a FragmentFactory will also affect child FragmentManagers. (aosp/1170095)

Dependency changes

Fragments now depends on Lifecycle 2.2.0-rc03 , Lifecycle ViewModel SavedState 1.0.0-rc03 , and Activity 1.1.0-rc03 .

Version 1.2.0-rc02

November 7, 2019

androidx.fragment:fragment:1.2.0-rc02 , androidx.fragment:fragment-ktx:1.2.0-rc02 , and androidx.fragment:fragment-testing:1.2.0-rc02 are released. Version 1.2.0-rc02 contains these commits.

Bug fixes

When in Kotlin, the LintFix for using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() (introduced in Fragment 1.2.0-rc01 ) now uses the Kotlin property access syntax viewLifecycleOwner instead of getViewLifecycleOwner() . (aosp/1143821)

Version 1.2.0-rc01

October 23, 2019

androidx.fragment:fragment:1.2.0-rc01 , androidx.fragment:fragment-ktx:1.2.0-rc01 , and androidx.fragment:fragment-testing:1.2.0-rc01 are released. Version 1.2.0-rc01 contains these commits.

New features

FragmentContainerView now supports the class attribute in addition to android:name , mirroring the functionality of the <fragment> tag. (b/142722242)

now supports the attribute in addition to , mirroring the functionality of the tag. (b/142722242) Added a new Lint check that ensures you are using getViewLifecycleOwner() when observing LiveData from onCreateView() , onViewCreated() , or onActivityCreated() . (b/137122478)

Bug fixes

The onDismiss and onCancel callbacks on DialogFragment now guarantee that the DialogInterface passed to them is non-null and that getDialog() returns non-null when they are executed. (b/141974033)

and callbacks on now guarantee that the passed to them is non-null and that returns non-null when they are executed. (b/141974033) FragmentContainerView now adds the Fragment defined by class or android:name as part of inflation, ensuring that findFragmentById() and findFragmentByTag() work immediately afterwards. (b/142520327)

now adds the Fragment defined by or as part of inflation, ensuring that and work immediately afterwards. (b/142520327) Fixed an IllegalStateException in FragmentContainerView due to the state being saved. (b/142580713)

in due to the state being saved. (b/142580713) Fixed an UnsupportedOperationException in FragmentContainerView when the FragmentContainerView class is obfuscated. (b/142657034)

Known issues

Fragments referenced only via the class or android:name attribute on a FragmentContainerView are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. We have disabled the Lint rule suggesting moving to FragmentContainerView until this is fixed via aapt2 . (b/142601969)

Version 1.2.0-beta02

October 11, 2019

androidx.fragment:fragment:1.2.0-beta02 , androidx.fragment:fragment-ktx:1.2.0-beta02 , and androidx.fragment:fragment-testing:1.2.0-beta02 are released. Version 1.2.0-beta02 contains these commits.

Bug fixes

Fixed an issue where Fragment's onInflate() did not receive proper attributes from FragmentContainerView , breaking cases such as NavHostFragment . (b/142421837)

Version 1.2.0-beta01

October 9, 2019

androidx.fragment:fragment:1.2.0-beta01 , androidx.fragment:fragment-ktx:1.2.0-beta01 , and androidx.fragment:fragment-testing:1.2.0-beta01 are released. Version 1.2.0-beta01 contains these commits.

New features

FragmentContainerView adds support for adding an initial fragment with added support for the android:name and optional android:tag XML attributes. Unlike the <fragment> tag, FragmentContainerView uses a normal FragmentTransaction under the hood to add the initial fragment, allowing further FragmentTransaction operations on the FragmentContainerView and enables the usage of View Binding for the layout. (b/139830628, b/141177981)

adds support for adding an initial fragment with added support for the and optional XML attributes. Unlike the tag, uses a normal under the hood to add the initial fragment, allowing further operations on the and enables the usage of View Binding for the layout. (b/139830628, b/141177981) Fragments now contains a Lint warning offering a quick fix to replace <fragment> with FragmentContainerView . (b/139830056)

Bug fixes

Fixed a ClassCastException when using androidx.transition . (b/140680619)

when using . (b/140680619) When using Transition 1.3.0-beta01 , Fragments now wait for androidx.transition transitions (in addition to framework transitions and animations, which were fixed in Fragment 1.2.0-alpha03 and Fragment 1.2.0-alpha02 , respectively) to finish before dispatching onDestroyView() . (aosp/1119841)

, Fragments now wait for transitions (in addition to framework transitions and animations, which were fixed in Fragment and Fragment , respectively) to finish before dispatching . (aosp/1119841) When using Transition 1.3.0-beta01 , Fragments now properly cancel androidx.transition transitions before starting new transitions / animations on the same container. (aosp/1119841)

, Fragments now properly cancel transitions before starting new transitions / animations on the same container. (aosp/1119841) Fixed an issue on API 17 and lower when using androidx.transition transitions on the root view of your Fragment when using FragmentContainerView . (b/140361893)

transitions on the root view of your Fragment when using . (b/140361893) The fragment-testing artifact now depends on AndroidX Test 1.2.0 , fixing an incompatibility with the latest Espresso 3.2.0. (b/139100149)

artifact now depends on AndroidX Test , fixing an incompatibility with the latest Espresso 3.2.0. (b/139100149) Removed usage of Log.w in FragmentManager. (aosp/1126468)

Known issues

Fragment's onInflate() do not receive proper attributes from FragmentContainerView , breaking cases such as NavHostFragment . (b/142421837)

Version 1.2.0-alpha04

September 18, 2019

androidx.fragment:fragment:1.2.0-alpha04 , androidx.fragment-ktx:example:1.2.0-alpha04 , and androidx.fragment:fragment-testing:1.2.0-alpha04 are released. Version 1.2.0-alpha04 contains these commits.

API changes

The getFragmentManager() and requireFragmentManager() methods on Fragment have been deprecated and replaced with a single getParentFragmentManager() method, which returns the non-null FragmentManager the Fragment is added to (you can use isAdded() to determine if it is safe to call). (b/140574496)

and methods on have been deprecated and replaced with a single method, which returns the non-null the Fragment is added to (you can use to determine if it is safe to call). (b/140574496) The static FragmentManager.enableDebugLogging method has been deprecated. FragmentManager now respects Log.isLoggable() for the tag FragmentManager , allowing you to enable either DEBUG or VERBOSE logging without re-compiling your app. (aosp/1116591)

Bug fixes

Fragments are now properly destroyed while exit animations on other fragments are running. (b/140574199)

Fixed an issue where Fragments would call Activity.findViewById() where before it did not. (aosp/1116431)

Version 1.2.0-alpha03

September 5, 2019

androidx.fragment:fragment:1.2.0-alpha03 , androidx.fragment:fragment-ktx:1.2.0-alpha03 , and androidx.fragment:fragment-testing:1.2.0-alpha03 are released. The commits included in this version can be found here.

API changes

FragmentContainerView is now final . (b/140133091)

Bug fixes

FragmentContainerView now properly reverses the draw order when popping fragments off the back stack. (b/139104187)

now properly reverses the draw order when popping fragments off the back stack. (b/139104187) Fixed an issue where the wrong animation would run when both popping a fragment and adding a new fragment at the same time. (b/111659726)

Fragments now wait for transitions (in addition to animations, which was fixed in Fragment 1.2.0-alpha02 ) to finish before dispatching onDestroyView() . (b/138741697)

Version 1.2.0-alpha02

August 7, 2019

androidx.fragment:fragment:1.2.0-alpha02 , androidx.fragment:fragment-ktx:1.2.0-alpha02 , and androidx.fragment:fragment-testing:11.2.0-alpha02 is released. The commits included in this version can be found here.

New features

SavedStateViewModelFactory is now the default factory used when using by viewModels() , by activityViewModels() , the ViewModelProvider constructor, or ViewModelProviders.of() with a Fragment . (b/135716331)

is now the default factory used when using , , the constructor, or with a . (b/135716331) The default animations when using TRANSIT_FRAGMENT_OPEN , TRANSIT_FRAGMENT_CLOSE , TRANSIT_FRAGMENT_FADE with setTransition on a FragmentTransaction have been updated to match the animations used by activities on Android 10 devices. (aosp/1012812, aosp/1014730)

API changes

Introduces FragmentContainerView as the strongly recommended container for dynamically added Fragments, replacing usage of FrameLayout , etc. as it fixes animation z-ordering issues and window insets dispatching to Fragments. (b/37036000, aosp/985243, b/136494650)

as the strongly recommended container for dynamically added Fragments, replacing usage of , etc. as it fixes animation z-ordering issues and window insets dispatching to Fragments. (b/37036000, aosp/985243, b/136494650) Added a static FragmentManager.findFragment(View) method to retrieve the containing Fragment from a view inflated by a fragment. A Kotlin extension is also available in fragment-ktx . (aosp/1090757)

method to retrieve the containing Fragment from a view inflated by a fragment. A Kotlin extension is also available in . (aosp/1090757) Added new overloads of add() and replace() on FragmentTransaction that take a Class<? extends Fragment> and optional Bundle of arguments. These methods use your FragmentFactory to construct an instance of the Fragment to add. Kotlin extension that use reified types (i.e, fragmentTransaction.replace<YourFragment>(R.id.container) ) have also been added to fragment-ktx . (b/126124987)

and on that take a and optional of arguments. These methods use your to construct an instance of the Fragment to add. Kotlin extension that use reified types (i.e, ) have also been added to . (b/126124987) @MainThread annotations have been added to Fragment lifecycle callbacks. (b/127272564)

annotations have been added to lifecycle callbacks. (b/127272564) The breadcrumb title related APIs on FragmentTransaction and FragmentManager.BackStackEntry have been deprecated. (b/138252944)

and have been deprecated. (b/138252944) The setTransitionStyle method on FragmentTransaction has been deprecated. (aosp/1011537)

method on has been deprecated. (aosp/1011537) Many of the methods in FragmentManager are no longer abstract . FragmentManager itself remains abstract and should not be directly instantiated or extended; you should continue to only get an existing instance from getSupportFragmentManager() , getChildFragmentManager() , etc.

Bug fixes

From Fragment 1.1.0-rc04 : Fragments now correctly cancel postponed transitions on Fragments have been popped. (b/138251858)

: Fragments now correctly cancel postponed transitions on Fragments have been popped. (b/138251858) From Fragment 1.1.0-rc03 : Fixed an issue where calling postponeEnterTransition() with a timeout more than once would not cancel previous timeouts. (b/137797118)

: Fixed an issue where calling with a timeout more than once would not cancel previous timeouts. (b/137797118) From Fragment 1.1.0-rc02 : Fixed a crash in FragmentPagerAdapter and FragmentStatePagerAdapter when removing the current item. (b/137209870)

: Fixed a crash in and when removing the current item. (b/137209870) Fragments now wait for animations to finish before dispatching onDestroyView() . (b/136110528)

. (b/136110528) Fragment animations from child fragments and their descendants are now properly handled when animating the parent Fragment. (b/116675313)

Fixed a NullPointerException when using shared element transitions and combining a pop and add operation. (b/120507394)

when using shared element transitions and combining a pop and add operation. (b/120507394) Added a workaround to IllegalStateException s when using FragmentPagerAdapter and FragmentStatePagerAdapter in Robolectric tests. (b/137201343)

Version 1.2.0-alpha01

July 2, 2019

androidx.fragment:fragment:1.2.0-alpha01 , androidx.fragment:fragment-ktx:1.2.0-alpha01 , and androidx.fragment:fragment-testing:1.2.0-alpha01 are released. The commits included in this version can be found here.

New features

FragmentManager now calls requestApplyInsets() after attaching the Fragment’s view and directly before calling onViewCreated() , ensuring that your view always has the correct insets. (b/135945162)

Bug fixes

Fixed a NullPointerException when popping a FragmentTransaction that used setPrimaryNavigationFragment() before replace() . (b/134673465)

Version 1.1.0

Version 1.1.0

September 5, 2019

androidx.fragment:fragment:1.1.0 , androidx.fragment:fragment-ktx:1.1.0 , and androidx.fragment:fragment-testing:1.1.0 are released. The commits included in this version can be found here.

Important Changes since 1.0.0

fragment-testing : The fragment-testing artifact provides a FragmentScenario class for testing a fragment in isolation. See Test your app’s fragments documentation for more details.

: The artifact provides a class for testing a fragment in isolation. See Test your app’s fragments documentation for more details. FragmentFactory : You can now set a FragmentFactory on a FragmentManager to manage the creation of fragment instances, removing the strict requirement to have a no-argument constructor.

: You can now set a on a to manage the creation of fragment instances, removing the strict requirement to have a no-argument constructor. Kotlin Property Delegates for ViewModels : The fragment-ktx artifact now contains two Kotlin property delegates: by viewModels() for accessing ViewModels associated with the individual fragment and by activityViewModels() for accessing ViewModels scoped to the activity.

: The artifact now contains two Kotlin property delegates: for accessing ViewModels associated with the individual fragment and for accessing ViewModels scoped to the activity. Max Lifecycle : You can now set a max Lifecycle state for a Fragment by calling setMaxLifecycle() on a FragmentTransaction . This replaces the now deprecated setUserVisibleHint() . FragmentPagerAdapter and FragmentStatePagerAdapter have a new constructor that allows you to switch to the new behavior.

: You can now set a max Lifecycle state for a Fragment by calling on a . This replaces the now deprecated . and have a new constructor that allows you to switch to the new behavior. FragmentActivity LayoutId constructor : Subclasses of FragmentActivity can now optionally call into a constructor on FragmentActivity that takes an R.layout ID, indicating the layout that should be set as the content view as an alternative to calling setContentView() in onCreate() . This does not change the requirement that your subclass have a no-argument constructor.

: Subclasses of can now optionally call into a constructor on that takes an ID, indicating the layout that should be set as the content view as an alternative to calling in . This does not change the requirement that your subclass have a no-argument constructor. Fragment LayoutId constructor : Subclasses of Fragment can now optionally call into a constructor on Fragment that takes an R.layout ID, indicating the layout that should be used for this fragment as an alternative to overriding onCreateView() . The inflated layout can be configured in onViewCreated() .

: Subclasses of can now optionally call into a constructor on that takes an ID, indicating the layout that should be used for this fragment as an alternative to overriding . The inflated layout can be configured in . Postpone with a timeout: A new overload of postponeEnterTransition() has been added that takes a timeout.

Version 1.1.0-rc04

August 7, 2019

androidx.fragment:fragment:1.1.0-rc04 , androidx.fragment:fragment-ktx:1.1.0-rc04 , and androidx.fragment:fragment-testing:1.1.0-rc04 is released. The commits included in this version can be found here.

Bug fixes

Fragments now correctly cancel postponed transitions on Fragments have been popped. (b/138251858)

Version 1.1.0-rc03

July 19, 2019

androidx.fragment:fragment:1.1.0-rc03 , androidx.fragment:fragment-ktx:1.1.0-rc03 , and androidx.fragment:fragment-testing:1.1.0-rc03 is released. The commits included in this version can be found here.

Bug fixes

Fixed an issue where calling postponeEnterTransition() with a timeout more than once would not cancel previous timeouts. (b/137797118)

Version 1.1.0-rc02

July 17, 2019

androidx.fragment:fragment:1.1.0-rc02 , androidx.fragment:fragment-ktx:1.1.0-rc02 , and androidx.fragment-testing:fragment:1.1.0-rc02 are released. The commits included in this version can be found here.

Bug fixes

Fixed a crash in FragmentPagerAdapter and FragmentStatePagerAdapter when removing the current item. (b/137209870)

Version 1.1.0-rc01

July 2, 2019

androidx.fragment:fragment:1.1.0-rc01 , androidx.fragment:fragment-ktx:1.1.0-rc01 , and androidx.fragment:fragment-testing:1.1.0-rc01 are released. The commits included in this version can be found here.

Bug fixes

Fragments now properly update their visibility when using show() or hide() operations while the transition is running. (b/133385058)

or operations while the transition is running. (b/133385058) Fixed a NullPointerException when popping a FragmentTransaction that used setPrimaryNavigationFragment() before replace() . (b/134673465)

Version 1.1.0-beta01

June 5, 2019

androidx.fragment:fragment:1.1.0-beta01 , androidx.fragment:fragment-ktx:1.1.0-beta01 , and androidx.fragment:fragment-testing:1.1.0-beta01 are released. The commits included in this version can be found here.

Bug fixes

androidx.lifecycle.Lifecycle callbacks (specifically related to STARTED , RESUMED , PAUSED , STOPPED , and DESTROYED ) for nested Fragments are now properly nested. (b/133497591)

callbacks (specifically related to , , , , and ) for nested Fragments are now properly nested. (b/133497591) OnBackPressedCallback instances registered in a Fragment’s onCreate() now properly take precedence over the child FragmentManager. (b/133175997)

instances registered in a Fragment’s now properly take precedence over the child FragmentManager. (b/133175997) Child fragments are no longer animated when their parent fragment is being replaced. (b/121017790)

Fragments animations and transitions are now ignored when using animateLayoutChanges="true" , fixing an issue where Fragments were not properly destroyed. (b/116257087)

Version 1.1.0-alpha09

May 16, 2019

androidx.fragment:fragment:1.1.0-alpha09 , androidx.fragment:fragment-ktx:1.1.0-alpha09 , and androidx.fragment:fragment-testing:1.1.0-alpha09 are released. The commits included in this version can be found here.

API changes

Fragments now receive a callback to a new onPrimaryNavigationFragmentChanged(boolean) method when the primary navigation fragment changes. aosp/960857

Bug fixes

Menu Items inflated by a child Fragment are now correctly removed when the Parent Fragment is removed. b/131581013

Version 1.1.0-alpha08

May 7, 2019

androidx.fragment:fragment:1.1.0-alpha08 , androidx.fragment:fragment-ktx:1.1.0-alpha08 , and androidx.fragment:fragment-testing:1.1.0-alpha08 are released. The commits included in this version can be found here.

This release is incompatible with Preferences 1.1.0-alpha01 through 1.1.0-alpha04. Please upgrade to Preferences 1.1.0-alpha05 when using this version of Fragments.

New features

Added a new overload of postponeEnterTransition() that takes a timeout, after which the Fragment will automatically call startPostponedEnterTransition() b/120803208

API changes

Breaking change: the previously deprecated FragmentFactory instantiate method that took a Bundle has been removed. aosp/953856

method that took a has been removed. aosp/953856 Breaking change: The RESUME_ONLY_CURRENT_FRAGMENT and USE_SET_USER_VISIBLE_HINT constants in FragmentPagerAdapter and FragmentStatePagerAdapter have been renamed to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT and BEHAVIOR_SET_USER_VISIBLE_HINT , respectively. aosp/954782

Bug fixes

Fragments that have had their lifecycle capped via setMaxLifecycle() no longer get resumed before reaching their final state. b/131557151

no longer get resumed before reaching their final state. b/131557151 When using setMaxLifecycle(Lifecycle.State.CREATED) , Fragments will properly have their view destroyed. aosp/954180

Version 1.1.0-alpha07

April 25, 2019

androidx.fragment:fragment:1.1.0-alpha07 , androidx.fragment:fragment-ktx:1.1.0-alpha07 , and androidx.fragment:fragment-testing:1.1.0-alpha07 are released. The commits included in this version can be found here.

New features

You can now set a max Lifecycle state for a Fragment by calling setMaxLifecycle() on a FragmentTransaction . This replaces the now deprecated setUserVisibleHint() . FragmentPagerAdapter and FragmentStatePagerAdapter have a new constructor that allows you to switch to the new behavior. (b/129780800)

API Changes

moveToState(STARTED) on FragmentScenario can now only be called on API 24+ devices. (b/129880016)

Behavior Changes

As a consequence of (b/129907905), fragments on the back stack will not get a callback to onCreateView() when the hosting activity is recreated. onCreateView() will now only be called when the fragment becomes visible (i.e., the back stack is popped).

Bug fixes

Fixed an issue when using a <fragment> tag in XML and the contentLayoutId constructor of FragmentActivity or AppCompatActivity . (b/129907905)

tag in XML and the constructor of or . (b/129907905) Corrected an issue where fragments on the back stack would not be moved to at least CREATED after a configuration change, causing ViewModels and child retained fragments to not be properly disposed. (b/129593351)

after a configuration change, causing ViewModels and child retained fragments to not be properly disposed. (b/129593351) Fixed a crash in restoreSaveState caused by a desync of the retained fragments after the instance state is saved. (b/130433793) (aosp/947824)

caused by a desync of the retained fragments after the instance state is saved. (b/130433793) (aosp/947824) Fixed issues where an OnBackPressedCallback added with a fragment lifecycle would not be called if the FragmentManager had a back stack. See androidx.activity 1.0.0-alpha07 for more details. (aosp/948209)

added with a fragment lifecycle would not be called if the had a back stack. See androidx.activity 1.0.0-alpha07 for more details. (aosp/948209) Fragments no longer enforce LAYER_TYPE_HARDWARE for animations. If you specifically need a hardware layer animation, please set it as part of your animation. (b/129486478)

Version 1.1.0-alpha06

April 3, 2019

androidx.fragment:fragment:1.1.0-alpha06 , androidx.fragment:fragment-ktx:1.1.0-alpha06 , and androidx.fragment:fragment-testing:1.1.0-alpha06 are released. The commits included in this version can be found here.

New features

Exceptions thrown by FragmentManager now include the Fragment’s name in the message. (b/67759402)

API Changes

Fragment and FragmentActivity now contain a second constructor that takes a @LayoutRes int , which replaces the previous behavior of annotating your class with @ContentView . This approach works in both app and library modules. (b/128352521)

and now contain a second constructor that takes a , which replaces the previous behavior of annotating your class with . This approach works in both app and library modules. (b/128352521) FragmentActivity’s onActivityResult() is now properly marked as @CallSuper . (b/127971684)

is now properly marked as . (b/127971684) The FragmentFactory’s instantiate method that takes an argument Bundle has been deprecated and apps should use the new instantiate overload that does not take a Bundle. (b/128836103)

method that takes an argument Bundle has been deprecated and apps should use the new overload that does not take a Bundle. (b/128836103) FragmentScenario methods are now properly annotated with @StyleRes . (aosp/924193)

methods are now properly annotated with . (aosp/924193) FragmentTabHost has been deprecated. (b/127971835)

has been deprecated. (b/127971835) FragmentActivity’s getThemedContext() has been removed. (aosp/934078)

Bug fixes

Fixed a regression in 1.1.0-alpha05 that caused the incoming Fragment to flash on the screen. (b/129405432)

Fixed an issue where the primary navigation fragment would be lost after a popBackStack+replace+popBackStack series of operations. (b/124332597)

Fixed an issue when using @ContentView constructors on your Activity when restoring Fragment state. (b/127313094)

constructors on your Activity when restoring Fragment state. (b/127313094) Corrected the logic of setTargetFragment() when replacing an existing target Fragment with a Fragment not yet attached to the FragmentManager. (aosp/932156)

Version 1.1.0-alpha05

March 13, 2019

androidx.fragment:fragment:1.1.0-alpha05 , androidx.fragment:fragment-ktx:1.1.0-alpha05 , and androidx.fragment:fragment-testing:1.1.0-alpha05 are released. The full list of commits included in this version can be found here.

New features

@ContentView annotation lookups are now cached (b/123709449)

Behavior changes

Calling remove() , hide() , show() , detach() , and setPrimaryNavigationFragment() with a Fragment attached to a different FragmentManager now throws an IllegalStateException rather than silently failing (aosp/904301)

Bug fixes

onNewIntent for FragmentActivity is now correctly marked with @CallSuper (b/124120586)

for is now correctly marked with (b/124120586) Fixed an issue where DialogFragment ’s onDismiss() could be called twice when using getDialog().dismiss() or getDialog().cancel() (b/126563750)

Version 1.1.0-alpha04

February 7, 2019

androidx.fragment:fragment 1.1.0-alpha04 , androidx.fragment:fragment-ktx 1.1.0-alpha04 , and androidx.fragment:fragment-testing 1.1.0-alpha04 are released.

New features

Added support for the @ContentView class annotation that allows you to indicate which layout XML file should be inflated as an alternative to overriding onCreateView() . It is recommended to do view related work in onViewCreated() . (aosp/837619)

class annotation that allows you to indicate which layout XML file should be inflated as an alternative to overriding . It is recommended to do view related work in . (aosp/837619) fragment-testing now depends on androidx.test:core-ktx 1.1.0 stable (b/121209673)

now depends on 1.1.0 stable (b/121209673) You can now use openActionBarOverflowOrOptionsMenu with FragmentScenario to test Fragment hosted options menus (b/121126668)

API changes

Added a requireArguments() method which returns a @NonNull Bundle or throws an IllegalStateException (b/121196360)

method which returns a or throws an (b/121196360) Added a note that getLifecycle() , getViewLifecycleOwner() , and getViewLifecycleOwnerLiveData() should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. (aosp/880714)

, , and should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. (aosp/880714) Added a note that getViewModelStore() should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. (aosp/880713)

should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. (aosp/880713) Fixed an issue with binary compatibility with previous releases of Fragments. (aosp/887877) (aosp/889834)

Bug fixes

Target fragments are correctly cleared out when you pass null to setTargetFragment() . (aosp/849969)

to . (aosp/849969) Fixed an issue where target Fragments were sometimes unavailable in or after onDestroy() . (b/122312935)

. (b/122312935) DialogFragment’s onDismiss() is now called before onDestroy() . (aosp/874133) (aosp/890734)

Version 1.1.0-alpha03

December 17, 2018

New features

Fragment now implements BundleSavedStateRegistryOwner and depends on the newly released SavedState library [aosp/824380]

and depends on the newly released SavedState library [aosp/824380] A by activityViewModels Kotlin property delegate has been added to retrieve ViewModels associated with the containing Activity [b/119050253]

Kotlin property delegate has been added to retrieve ViewModels associated with the containing Activity [b/119050253] The by viewModels Kotlin property delegate has been expanded to take an optional lambda method for getting the ViewModelStoreOwner , allowing you to pass in the parent Fragment or other custom ViewModelStoreOwner with code such as val viewModel: MyViewModel by viewModels(::requireParentFragment) [b/119050253]

API changes

FragmentScenario now allows you to specify a theme such as Theme.AppCompat [b/119054431]. This is a breaking change.

now allows you to specify a theme such as [b/119054431]. This is a breaking change. Added a requireView() method which returns a @NonNull View or throws an IllegalStateException [b/120241368]

method which returns a or throws an [b/120241368] Added a requireParentFragment() method which returns a @NonNull Fragment or throws an IllegalStateException [b/112103783]

Bug fixes

Fixed IllegalStateException: Failure saving state b/120814739

Fragments being restored from saved instance state will now always receive a non-null Bundle [b/119794496]

[b/119794496] Removed Fragments no longer reuse their Lifecycle object if re-added [b/118880674]

Version 1.1.0-alpha02

December 3, 2018

New features

FragmentScenario’s Kotlin extensions now let you use a lambda for Fragment construction as an alternative to passing in a FragmentFactory instance. (aosp/812913)

Bug fixes

Fixed an IllegalStateException when using nested Fragments on the back stack (b/119256498)

Fixed crash when using FragmentScenario.recreate() with a FragmentFactory (aosp/820540)

with a (aosp/820540) Fixed an issue where target Fragments were not accessible after the Fragment was removed (aosp/807634)

Version 1.1.0-alpha01

November 5, 2018

This is the first release of the fragment-testing artifact and FragmentScenario which is built on top of the androidx.test:core APIs. See the Fragment testing documentation for more details.

New features

New FragmentScenario class for testing Fragments in isolation.

You can now set a FragmentFactory on any FragmentManager to control how new Fragment instances are instantiated.

on any to control how new Fragment instances are instantiated. Added a new by viewModels() Kotlin property delegate for retrieving ViewModels from a Fragment.

Kotlin property delegate for retrieving ViewModels from a Fragment. Pending input events (such as clicks) are now canceled in a Fragment’s onStop() .

API changes

Significantly expanded the nullability annotations across the Fragment API surface.

Bug fixes

Fix an issue which caused Fragment operations to fail from within LiveData (b/77944637)

Known issues