| Latest Update | Current Stable Release | Next Release Candidate | Beta Release | Alpha Release |
|---|---|---|---|---|
| July 22, 2020 | 1.2.5 | - | - | 1.3.0-alpha07 |
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. Please 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.
See the Issue Tracker documentation for more information.
Version 1.3.0
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
FragmentScenarionow supports setting an initial Lifecycle state ofCREATED,STARTED, orRESUMEDrather than always moving the Fragment to theRESUMEDstate. (b/159662750)- Added an alternative to the
FragmentScenarioAPI ofonFragmentin the form of the Kotlin reified extension methodwithFragmentthat allows you to return a value. Notably, it rethrows exceptions raised in the given block. (b/158697631)
Behavior Changes
FragmentScenarionow usessetMaxLifecycle()to implementmoveToState(), ensuring consistent behavior on all API levels and decoupling the Fragment’s state from the underlying Activity. (b/156527405)- The
SavedStateRegistryOwnerreturned byViewTreeSavedStateRegistryOwneris 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) - Calling
clearFragmentResultListenernow 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 onFragmentActivityandFragmenthave been deprecated. A newFragmentOnAttachListenerhas been added to provide a more flexible alternative, allowing delegation ofonAttachFragment()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
DialogFragmentwould show anotherDialogFragmentas a child fragment. (b/157195715) - Fixed an issue where the
UseRequireInsteadOfGetLint 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
ViewTreeViewModelStoreOwnerfrom Lifecycle2.3.0-alpha03, andViewTreeSavedStateRegistryOwnerfrom SavedState1.1.0-alpha01when using aViewwithin aFragment. (aosp/1297993, aosp/1300264)
API Changes
- The
setFragmentResult()andsetFragmentResultListener()APIs now take a non-nullBundleandFragmentResultListener, respectively. To explicitly clear a previously set result or listener, use the newclearFragmentResult()andclearFragmentResultListener()methods. (b/155416778) - The
setFragmentResultListener()Kotlin extensions that take a lambda are now marked asinline. (b/155323404)
Behavior Changes
- The previously deprecated
startActivityForResult(),startIntentSenderForResult(), andrequestPermissionsonFragmentnow internally useActivityResultRegistry, thus removing the restriction on using only the lower bits (below0xFFFF) for your request codes when using those APIs. (b/155518741)
Documentation Updates
- Expanded the documentation on the
Fragment(@LayoutRes int)andDialogFragment(@LayoutRes int)constructors to clarify that they should be called from your subclasses’ no argument constructor when using the defaultFragmentFactory. (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 leastSTARTED. (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()andrequestPermissions()/onRequestPermissionsResult()APIs on Fragment have been deprecated. Please use the Activity Result APIs. (aosp/1290887) - Breaking change from Activity
1.2.0-alpha04: theprepareCall()method has been renamed toregisterForActivityResult(). (aosp/1278717)
Bug Fixes
- The fragment’s
getViewLifecycleOwner()is now stopped beforeonSaveInstanceState()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) - Fixed an
illegalStateExceptionwhen adding a fragment to aDialogFragment’s view hierarchy withFragmentContainerView. (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
prepareCallmethods onFragmentare nowfinal. (b/152439361)
Bug Fixes
- Fixed a regression introduced in Fragment
1.3.0-alpha02when usingBottomSheetDialogFragment. (b/151652127, aosp/1263328, aosp/1265163) - Fixed a crash when using
prepareCallfrom a fragment after a configuration change. (b/152137004) - Fixed an issue where shared element and exit transitions are ignored when using
setTargetFragment(). (b/152023196) - From Fragment
1.2.4: Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. (b/151605338) - From Fragment
1.2.4: Disabled theFragmentLiveDataObserveLint rule onDialogFragmentclasses as their lifecycle and view lifecycle are always in sync, making it safe to use eitherthisorviewLifecycleOwnerwhen callingobserve. (b/151765086)
Dependency Changes
- Fragments depend on Activity
1.2.0-alpha03, which had significant improvements to the Activity Result API introduced in Activity1.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
ActivityResultRegistryAPI introduced in Activity1.2.0-alpha02to handle thestartActivityForResult()+onActivityResult()as well asrequestPermissions()+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
DialogFragmentnow provides a constructor that takes a@LayoutResthat indicates the layout thatonCreateView()should inflate by default. (b/150327080)- The
onActivityCreated()method is now deprecated. Code touching the fragment's view should be done inonViewCreated()(which is called immediately beforeonActivityCreated()) and other initialization code should be inonCreate(). To receive a callback specifically when the activity'sonCreate()is complete, aLifeCycleObservershould be registered on the activity'sLifecycleinonAttach(), and removed once theonCreate()callback is received. (b/144309266)
Bug Fixes
- From Fragment
1.2.3: Fixed a bug inDialogFragmentthat caused aStackOverflowErrorwhen callinggetLayoutInflater()from withinonCreateDialog(). (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) - From Fragment
1.2.3: Fixed false positives in theUseRequireInsteadOfGetLint check when using a local variable name that shadowed the Kotlin property name. (b/149891163) - From Fragment
1.2.3:FragmentContainerViewno longer throws anUnsupportedOperationExceptionfor using the incorrect constructor in layout preview. (b/149707833)
Known Issues
BottomSheetDialogFragmentno 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 Lifecycle2.3.0-alpha01such that it will return the Fragment’sviewLifecycleOwneras theLifecycleOwnerfor any Views returned byonCreateView(). (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 theViewModeland theonCleared()callback it receives). (b/143911815) - With the release of ViewPager2
1.0.0, theFragmentPagerAdapterandFragmentStatePagerAdapterclasses for interacting withViewPagerhave been deprecated. See Migrate from ViewPager to ViewPager2. (b/145132715)
Bug Fixes
- Fragment ProGuard rules now correctly only keep the default constructors
Fragmentclasses that are used rather than for allFragmentinstances, fixing a regression introduced in Fragment1.2.1. (b/149665169 - The
require___()Lint rules added in Fragment1.2.2no longer false positive on local variables that share the same name as the shadowed Kotlin property names (i.e.,view). (b/149891163) FragmentContainerViewno longer throws anUnsupportedOperationExceptionwhen 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
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 beforeonSaveInstanceState()is called, mirroring the behavior of the fragment’s lifecycle. This was previously released in Fragment1.3.0-alpha04. (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 Fragment1.3.0-alpha04. (b/153593580)
Version 1.2.4
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
FragmentLiveDataObserveLint rule onDialogFragmentclasses as their lifecycle and view lifecycle are always in sync, making it safe to use eitherthisorviewLifecycleOwnerwhen callingobserve. (b/151765086)
Version 1.2.3
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
DialogFragmentthat caused aStackOverflowErrorwhen callinggetLayoutInflater()from withinonCreateDialog(). (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
UseRequireInsteadOfGetLint check when using a local variable name that shadowed the Kotlin property name. (b/149891163) FragmentContainerViewno longer throws anUnsupportedOperationExceptionfor using the incorrect constructor in layout preview. (b/149707833)
Version 1.2.2
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
viewLifecycleOwneras theLifecycleOwnerto calls intoOnBackPressedDispatcherinonCreateView(),onViewCreated(), andonActivityCreated(). (b/142117657) - Added a new Lint check that confirms that you are using the correct
debugImplementationwhen using thefragment-testingartifact. (b/141500106) - Fragments now suggest using the associated
require___()methods for more descriptive error messages instead ofcheckNotNull(get___()),requireNonNull(get___()), orget___()!!for all of the Fragment APIs that include both agetandrequireequivalent. (aosp/1202883)
Bug Fixes
- Fixed the Fragment ProGuard files to avoid R8 warnings (b/148963981)
- Improved the existing Lint check suggesting using
viewLifecycleOwnerwhen usingobserveto also handle thelivedata-ktxextension method version ofobserve. (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
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
addandreplacemethods that take aClassinstance (or the Kotlin reified versions) now have their default constructor kept by ProGuard. (b/148181315) FragmentStatePagerAdapterandFragmentPagerAdapterno longer catch exceptions thrown byFragmentManagerwhen runningfinishUpdate(). (aosp/1208711)- Fixed an issue where
FragmentManager.findFragment()did not work with fragments added via the<fragment>tag. (b/147784323) - Fragments inflated using the
<fragment>tag now always receive a call toonInflate()beforeonCreate()when in the layout. (aosp/1215856) - Calling
toString()on aFragmentManagerinstance no longer throws aNullPointerExceptionwhen the Activity is already destroyed. (b/148189412)
Dependency changes
- Fragments
1.2.1now depends on Lifecycle ViewModel SavedState2.2.0.
Version 1.2.0
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
FragmentContainerViewis the strongly recommended container for dynamically added Fragments, replacing usage ofFrameLayoutor other layouts. It also supports the sameclass,android:name, and optionalandroid:tagas the<fragment>tag, but uses a normalFragmentTransactionto add this initial fragment, instead of the custom code path used by<fragment>. onDestroyView()timing: Fragments now wait for exit animations, exit framework transitions, and exit AndroidX transitions (when using Transition1.3.0) to complete before callingonDestroyView().- Class based
add()andreplace(): Added new overloads ofadd()andreplace()onFragmentTransactionthat take aClass<? extends Fragment>and optionalBundleof arguments. These methods use yourFragmentFactoryto 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 tofragment-ktx. - Lifecycle ViewModel SavedState Integration:
SavedStateViewModelFactoryis now the default factory used when usingby viewModels(),by activityViewModels(), theViewModelProviderconstructor, orViewModelProviders.of()with a Fragment. - New Lint checks: Added a new Lint check that ensures you are using
getViewLifecycleOwner()when observingLiveDatafromonCreateView(),onViewCreated(), oronActivityCreated(). getFragmentManager()deprecation: ThegetFragmentManager()andrequireFragmentManager()methods on Fragment have been deprecated and replaced with a singlegetParentFragmentManager()method, which returns the non-nullFragmentManagerthe Fragment is added to (you can useisAdded()to determine if it is safe to call).FragmentManager.enableDebugLogging()deprecation: The staticFragmentManager.enableDebugLoggingmethod has been deprecated. FragmentManager now respectsLog.isLoggable()for the tagFragmentManager, allowing you to enable eitherDEBUGorVERBOSElogging without re-compiling your app.
Known Issues
- Fragments referenced only via the
classorandroid:nameattribute on aFragmentContainerVieware not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. (b/142601969) - When adding a
NavHostFragmentusingclassorandroid:namein XML withFragmentContainerView, you cannot usefindNavController()inonCreate()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-rc04when using the<fragment>tag which causedonViewCreated()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 toCREATEDeven 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, andTRANSIT_FRAGMENT_FADEto 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) - Child fragments are now correctly stopped before their parents when the containing activity calls
onSaveInstanceState(). (b/144380645) - Fixed an issue where Views were incorrectly marked
INVISIBLEafter 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) - Improved the documentation on
setFragmentFactory()andgetFragmentFactory()to better indicate that setting aFragmentFactorywill also affect child FragmentManagers. (aosp/1170095)
Dependency changes
- Fragments now depends on Lifecycle
2.2.0-rc03, Lifecycle ViewModel SavedState1.0.0-rc03, and Activity1.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 observingLiveDatafromonCreateView(),onViewCreated(), oronActivityCreated()(introduced in Fragment1.2.0-rc01) now uses the Kotlin property access syntaxviewLifecycleOwnerinstead ofgetViewLifecycleOwner(). (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
FragmentContainerViewnow supports theclassattribute in addition toandroid:name, mirroring the functionality of the<fragment>tag. (b/142722242)- Added a new Lint check that ensures you are using
getViewLifecycleOwner()when observingLiveDatafromonCreateView(),onViewCreated(), oronActivityCreated(). (b/137122478)
Bug fixes
- The
onDismissandonCancelcallbacks onDialogFragmentnow guarantee that theDialogInterfacepassed to them is non-null and thatgetDialog()returns non-null when they are executed. (b/141974033) FragmentContainerViewnow adds the Fragment defined byclassorandroid:nameas part of inflation, ensuring thatfindFragmentById()andfindFragmentByTag()work immediately afterwards. (b/142520327)- Fixed an
IllegalStateExceptioninFragmentContainerViewdue to the state being saved. (b/142580713) - Fixed an
UnsupportedOperationExceptioninFragmentContainerViewwhen theFragmentContainerViewclass is obfuscated. (b/142657034)
Known issues
- Fragments referenced only via the
classorandroid:nameattribute on aFragmentContainerVieware 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 toFragmentContainerViewuntil this is fixed viaaapt2. (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 fromFragmentContainerView, breaking cases such asNavHostFragment. (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
FragmentContainerViewadds support for adding an initial fragment with added support for theandroid:nameand optionalandroid:tagXML attributes. Unlike the<fragment>tag,FragmentContainerViewuses a normalFragmentTransactionunder the hood to add the initial fragment, allowing furtherFragmentTransactionoperations on theFragmentContainerViewand 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>withFragmentContainerView. (b/139830056)
Bug fixes
- Fixed a
ClassCastExceptionwhen usingandroidx.transition. (b/140680619) - When using Transition
1.3.0-beta01, Fragments now wait forandroidx.transitiontransitions (in addition to framework transitions and animations, which were fixed in Fragment1.2.0-alpha03and Fragment1.2.0-alpha02, respectively) to finish before dispatchingonDestroyView(). (aosp/1119841) - When using Transition
1.3.0-beta01, Fragments now properly cancelandroidx.transitiontransitions before starting new transitions / animations on the same container. (aosp/1119841) - Fixed an issue on API 17 and lower when using
androidx.transitiontransitions on the root view of your Fragment when usingFragmentContainerView. (b/140361893) - The
fragment-testingartifact now depends on AndroidX Test1.2.0, fixing an incompatibility with the latest Espresso 3.2.0. (b/139100149) - Removed usage of
Log.win FragmentManager. (aosp/1126468)
Known issues
- Fragment's
onInflate()do not receive proper attributes fromFragmentContainerView, breaking cases such asNavHostFragment. (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()andrequireFragmentManager()methods onFragmenthave been deprecated and replaced with a singlegetParentFragmentManager()method, which returns the non-nullFragmentManagerthe Fragment is added to (you can useisAdded()to determine if it is safe to call). (b/140574496) - The static
FragmentManager.enableDebugLoggingmethod has been deprecated. FragmentManager now respectsLog.isLoggable()for the tagFragmentManager, allowing you to enable eitherDEBUGorVERBOSElogging 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
FragmentContainerViewis nowfinal. (b/140133091)
Bug fixes
FragmentContainerViewnow 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 dispatchingonDestroyView(). (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
SavedStateViewModelFactoryis now the default factory used when usingby viewModels(),by activityViewModels(), theViewModelProviderconstructor, orViewModelProviders.of()with aFragment. (b/135716331)- The default animations when using
TRANSIT_FRAGMENT_OPEN,TRANSIT_FRAGMENT_CLOSE,TRANSIT_FRAGMENT_FADEwithsetTransitionon aFragmentTransactionhave been updated to match the animations used by activities on Android 10 devices. (aosp/1012812, aosp/1014730)
API changes
- Introduces
FragmentContainerViewas the strongly recommended container for dynamically added Fragments, replacing usage ofFrameLayout, 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 infragment-ktx. (aosp/1090757) - Added new overloads of
add()andreplace()onFragmentTransactionthat take aClass<? extends Fragment>and optionalBundleof arguments. These methods use yourFragmentFactoryto 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 tofragment-ktx. (b/126124987) @MainThreadannotations have been added toFragmentlifecycle callbacks. (b/127272564)- The breadcrumb title related APIs on
FragmentTransactionandFragmentManager.BackStackEntryhave been deprecated. (b/138252944) - The
setTransitionStylemethod onFragmentTransactionhas been deprecated. (aosp/1011537) - Many of the methods in
FragmentManagerare no longerabstract.FragmentManageritself remainsabstractand should not be directly instantiated or extended; you should continue to only get an existing instance fromgetSupportFragmentManager(),getChildFragmentManager(), etc.
Bug fixes
- From Fragment
1.1.0-rc04: Fragments now correctly cancel postponed transitions on Fragments have been popped. (b/138251858) - From Fragment
1.1.0-rc03: Fixed an issue where callingpostponeEnterTransition()with a timeout more than once would not cancel previous timeouts. (b/137797118) - From Fragment
1.1.0-rc02: Fixed a crash inFragmentPagerAdapterandFragmentStatePagerAdapterwhen removing the current item. (b/137209870) - Fragments now wait for animations to finish before dispatching
onDestroyView(). (b/136110528) - Fragment animations from child fragments and their descendants are now properly handled when animating the parent Fragment. (b/116675313)
- Fixed a
NullPointerExceptionwhen using shared element transitions and combining a pop and add operation. (b/120507394) - Added a workaround to
IllegalStateExceptions when usingFragmentPagerAdapterandFragmentStatePagerAdapterin 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 callingonViewCreated(), ensuring that your view always has the correct insets. (b/135945162)
Bug fixes
- Fixed a
NullPointerExceptionwhen popping aFragmentTransactionthat usedsetPrimaryNavigationFragment()beforereplace(). (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-testingartifact provides aFragmentScenarioclass for testing a fragment in isolation. See Test your app’s fragments documentation for more details. - FragmentFactory: You can now set a
FragmentFactoryon aFragmentManagerto manage the creation of fragment instances, removing the strict requirement to have a no-argument constructor. - Kotlin Property Delegates for ViewModels: The
fragment-ktxartifact now contains two Kotlin property delegates:by viewModels()for accessing ViewModels associated with the individual fragment andby activityViewModels()for accessing ViewModels scoped to the activity. - Max Lifecycle: You can now set a max Lifecycle state for a Fragment by calling
setMaxLifecycle()on aFragmentTransaction. This replaces the now deprecatedsetUserVisibleHint().FragmentPagerAdapterandFragmentStatePagerAdapterhave a new constructor that allows you to switch to the new behavior. - FragmentActivity LayoutId constructor: Subclasses of
FragmentActivitycan now optionally call into a constructor onFragmentActivitythat takes anR.layoutID, indicating the layout that should be set as the content view as an alternative to callingsetContentView()inonCreate(). This does not change the requirement that your subclass have a no-argument constructor. - Fragment LayoutId constructor: Subclasses of
Fragmentcan now optionally call into a constructor onFragmentthat takes anR.layoutID, indicating the layout that should be used for this fragment as an alternative to overridingonCreateView(). The inflated layout can be configured inonViewCreated(). - 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
FragmentPagerAdapterandFragmentStatePagerAdapterwhen 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()orhide()operations while the transition is running. (b/133385058) - Fixed a
NullPointerExceptionwhen popping aFragmentTransactionthat usedsetPrimaryNavigationFragment()beforereplace(). (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.Lifecyclecallbacks (specifically related toSTARTED,RESUMED,PAUSED,STOPPED, andDESTROYED) for nested Fragments are now properly nested. (b/133497591)OnBackPressedCallbackinstances registered in a Fragment’sonCreate()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 callstartPostponedEnterTransition()b/120803208
API changes
- Breaking change: the previously deprecated
FragmentFactoryinstantiatemethod that took aBundlehas been removed. aosp/953856 - Breaking change: The
RESUME_ONLY_CURRENT_FRAGMENTandUSE_SET_USER_VISIBLE_HINTconstants inFragmentPagerAdapterandFragmentStatePagerAdapterhave been renamed toBEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENTandBEHAVIOR_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 - 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 aFragmentTransaction. This replaces the now deprecatedsetUserVisibleHint().FragmentPagerAdapterandFragmentStatePagerAdapterhave a new constructor that allows you to switch to the new behavior. (b/129780800)
API Changes
moveToState(STARTED)onFragmentScenariocan 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 thecontentLayoutIdconstructor ofFragmentActivityorAppCompatActivity. (b/129907905) - Corrected an issue where fragments on the back stack would not be moved to at least
CREATEDafter a configuration change, causing ViewModels and child retained fragments to not be properly disposed. (b/129593351) - Fixed a crash in
restoreSaveStatecaused by a desync of the retained fragments after the instance state is saved. (b/130433793) (aosp/947824) - Fixed issues where an
OnBackPressedCallbackadded with a fragment lifecycle would not be called if theFragmentManagerhad a back stack. See androidx.activity 1.0.0-alpha07 for more details. (aosp/948209) - Fragments no longer enforce
LAYER_TYPE_HARDWAREfor 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
FragmentandFragmentActivitynow 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)- FragmentActivity’s
onActivityResult()is now properly marked as@CallSuper. (b/127971684) - The FragmentFactory’s
instantiatemethod that takes an argument Bundle has been deprecated and apps should use the newinstantiateoverload that does not take a Bundle. (b/128836103) FragmentScenariomethods are now properly annotated with@StyleRes. (aosp/924193)FragmentTabHosthas 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
@ContentViewconstructors 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
@ContentViewannotation lookups are now cached (b/123709449)
Behavior changes
- Calling
remove(),hide(),show(),detach(), andsetPrimaryNavigationFragment()with a Fragment attached to a different FragmentManager now throws anIllegalStateExceptionrather than silently failing (aosp/904301)
Bug fixes
onNewIntentforFragmentActivityis now correctly marked with@CallSuper(b/124120586)- Fixed an issue where
DialogFragment’sonDismiss()could be called twice when usinggetDialog().dismiss()orgetDialog().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
@ContentViewclass annotation that allows you to indicate which layout XML file should be inflated as an alternative to overridingonCreateView(). It is recommended to do view related work inonViewCreated(). (aosp/837619) fragment-testingnow depends onandroidx.test:core-ktx1.1.0 stable (b/121209673)- You can now use
openActionBarOverflowOrOptionsMenuwithFragmentScenarioto test Fragment hosted options menus (b/121126668)
API changes
- Added a
requireArguments()method which returns a@NonNull Bundleor throws anIllegalStateException(b/121196360) - Added a note that
getLifecycle(),getViewLifecycleOwner(), andgetViewLifecycleOwnerLiveData()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) - 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
nulltosetTargetFragment(). (aosp/849969) - Fixed an issue where target Fragments were sometimes unavailable in or after
onDestroy(). (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
BundleSavedStateRegistryOwnerand depends on the newly released SavedState library [aosp/824380] - A
by activityViewModelsKotlin property delegate has been added to retrieve ViewModels associated with the containing Activity [b/119050253] - The
by viewModelsKotlin property delegate has been expanded to take an optional lambda method for getting theViewModelStoreOwner, allowing you to pass in the parent Fragment or other customViewModelStoreOwnerwith code such asval viewModel: MyViewModel by viewModels(::requireParentFragment)[b/119050253]
API changes
FragmentScenarionow allows you to specify a theme such asTheme.AppCompat[b/119054431]. This is a breaking change.- Added a
requireView()method which returns a@NonNull Viewor throws anIllegalStateException[b/120241368] - Added a
requireParentFragment()method which returns a@NonNull Fragmentor throws anIllegalStateException[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] - Removed Fragments no longer reuse their
Lifecycleobject 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
FragmentFactoryinstance. (aosp/812913)
Bug fixes
- Fixed an IllegalStateException when using nested Fragments on the back stack (b/119256498)
- Fixed crash when using
FragmentScenario.recreate()with aFragmentFactory(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
FragmentFactoryon anyFragmentManagerto control how new Fragment instances are instantiated. - Added a new
by viewModels()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
- Target Fragments cannot be accessed after a Fragment has been removed from the FragmentManager.
fragment-testingdepends onandroidx.test:core:1.0.0-beta01instead of the correctandroidx.test:core:1.0.0.

