Fragment
Latest Update | Current Stable Release | Next Release Candidate | Beta Release | Alpha Release |
---|---|---|---|---|
December 16, 2020 | 1.2.5 | 1.3.0-rc01 | - | - |
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.
See the Issue Tracker documentation for more information.
Version 1.3.0
Version 1.3.0-rc01
December 16, 2020
androidx.fragment:fragment:1.3.0-rc01
, androidx.fragment:fragment-ktx:1.3.0-rc01
, and androidx.fragment:fragment-testing:1.3.0-rc01
are released. Version 1.3.0-rc01 contains these commits.
Bug Fixes
onPrepareOptionsMenu()
now follows the same logic asonCreateOptionsMenu()
and is no longer called when a parent fragment callssetMenuVisibility(false)
. (Id7de8, b/173203654)
New State Manager Bug Fixes
- Fixed leak and visual artifact when adding
a fragment with an
Animation
to aFragmentContainerView
and then interrupting that addition with a pop operation. (I952d8) - Fixed an issue where the fragment's view would
remain in the view hierarchy if it was replaced during
its
onCreate()
oronViewCreated()
methods. (I8a7d5) - Focus is now properly restored to Fragment root views when they are resumed. (Ifc84b)
- Combining pop and replace operations in the same fragment transaction will now show the proper animations (Ifd4e4, b/170328691)
Version 1.3.0-beta02
December 2, 2020
androidx.fragment:fragment:1.3.0-beta02
, androidx.fragment:fragment-ktx:1.3.0-beta02
, and androidx.fragment:fragment-testing:1.3.0-beta02
are released. Version 1.3.0-beta02 contains these commits.
New Features
FragmentScenario
has been fully converted to Kotlin while maintaining source and binary compatibility via usage of Kotlin 1.4's functional interfaces forFragmentAction
. (I19d31)
Behavior Changes
- FragmentContainerViews that do not inflate a fragment using the
class
orandroid:name
attribute can now be used outside of aFragmentActivity
. (Id4397, b/172266337) - Attempting to set the max lifecycle of a fragment to
DESTROYED
will now throw anIllegalArgumentException
(Ie7651, b/170765622) - Initializing a FragmentScenario with a
DESTROYED
state will now throw anIllegalArgumentException
(I73590, b/170765622)
New State Manager Bug Fixes
- Fixed an issue where the view would not reach its final state if you interrupt a fragment transition that was using an
Animator
or one of theTRANSIT_FRAGMENT_
options. (I92426, b/169874632) - Fixed an issue that prevented fragments with an exiting
Animation
from being properly destroyed. (I83d65) - Exiting fragments that have their effects reversed now correctly cancel and restart with the proper entering effect. (I62226, b/167092035)
- Fixed an issue where the exit
Animator
of ahide()
would not run. (Id7ffe) - Fragments now properly appear when postponed and then immediately started. (Ie713b, b/170022857)
- Fragments that remove their focused view during an animation will no longer attempt to restore the focus on the detached view once they reach
RESUMED
(I38c65, b/172925703)
External Contribution
FragmentFactory
now caches fragment classes separately for differentClassLoader
instances. Thanks Simon Schiller! (#87, b/113886460)
Version 1.3.0-beta01
October 1, 2020
androidx.fragment:fragment:1.3.0-beta01
, androidx.fragment:fragment-ktx:1.3.0-beta01
, and androidx.fragment:fragment-testing:1.3.0-beta01
are released. Version 1.3.0-beta01 contains these commits.
New Features
setMaxLifecycle()
now supports setting theLifecycle
state toINITIALIZING
as long as the fragment has not been moved toCREATED
. (b/159662173)
API Changes
- Upgrade androidx to use Kotlin 1.4 (Id6471, b/165307851, b/165300826)
Behavior Changes
- Fragment resource files have been correctly made private. (aosp/1425237)
Bug Fixes
- Fragments inflated using the
<fragment>
tag will now properly wait until their views are added to a container before moving to STARTED (I02f4c) - Fragments that are visible and then
setMaxLifecycle()
toCREATED
now properly run their exit effects. (b/165822335) - Removing a detached fragment that is not added to the back stack no longer causes a memory leak. Courtesy of Nicklas Ansman Giertz! (b/166489383)
- Active fragments will now always have a non-null
FragmentManager
and fragments with a non-nullFragmentManager
will always be considered active. (aosp/1422346) - The fragment default effects,
TRANSIT_FRAGMENT_OPEN
,TRANSIT_FRAGMENT_CLOSE
, andTRANSIT_FRAGMENT_FADE
, now useAnimator
instead ofAnimation
. (b/166155034)
New State Manager Bug Fixes
- Fragments now properly restore their view focus state from right before they start their animation. (Icc256)
- Fragments that only have a shared element transition now properly complete their special effects meaning they actually move to their final state (Iaebc7, b/166658128)
- Fragment views are now always removed from the container before being destroyed. (Id5876)
- The new state manager now consistently removes the exiting fragment view before adding the entering one. (I41a6e)
- Explicit changes to a fragment view’s visibility are now respected by the new state manager. This means that if you set an entering fragment’s view to
INVISIBLE
before the animation begins, it will actually stay invisible. (b/164481490) - Fragments now prioritize
Animators
overAnimations
, meaning a fragment with both will only run theAnimator
and ignore theAnimation
. (b/167579557) - The new state manager no longer causes fragments to flash when using entering animations. (b/163084315)
Known Issue
When using the new state manager, if you press back during an entering special effect instead of returning to the previous fragment, the old fragment is never re-added, resulting in a blank screen. (b/167259187, b/167092035, b/168442830)
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) - Fragments now prevent multiple competing animations on the same fragments, avoiding cases where an
Animation
would override allTransition
effects or anAnimator
and aTransition
on an individual fragment would both run. (b/149569323) - The
enterTransition
andexitTranstion
of all 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 toSTARTED
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) - 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 callingfindFragmentById()
orfindFragmentByTag()
from within theonAttachFragment()
callback. (b/153082833)- Fragments no longer call
onCreateView()
on fragments being destroyed when the fragment replacing them is postponed. (b/143915710) - The error message when attempting to combine framework
Transition
and AndroidXTransition
instances now mentions the fragment with the invalid transition. (b/155574969)
Behavior Changes
- You can now call
launch()
on anActivityResultLauncher
in theonCreate()
lifecycle method of a fragment. (b/161464278) - Calling
registerForActivityResult()
afteronCreate()
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 theOnContextAvailableListener
API introduced in Activity1.2.0-alpha08
to restore the state of theFragmentManager
. Any listeners added to subclasses ofFragmentActivity
will run after this listener. (I513da)
Bug Fixes
ActivityOptions
passed through when usingstartIntentSenderForResult()
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 beforeonResume()
results in the visibility you set being overridden byFragmentManager
, who controls the visibility of the root view. As a workaround, you should always use thehide()
andshow()
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 ofCREATED
,STARTED
, orRESUMED
rather than always moving the Fragment to theRESUMED
state. (b/159662750)- Added an alternative to the
FragmentScenario
API ofonFragment
in the form of the Kotlin reified extension methodwithFragment
that allows you to return a value. Notably, it rethrows exceptions raised in the given block. (b/158697631)
Behavior Changes
FragmentScenario
now usessetMaxLifecycle()
to implementmoveToState()
, ensuring consistent behavior on all API levels and decoupling the Fragment’s state from the underlying Activity. (b/156527405)- The
SavedStateRegistryOwner
returned byViewTreeSavedStateRegistryOwner
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) - 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 onFragmentActivity
andFragment
have been deprecated. A newFragmentOnAttachListener
has 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
DialogFragment
would show anotherDialogFragment
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 Lifecycle2.3.0-alpha03
, andViewTreeSavedStateRegistryOwner
from SavedState1.1.0-alpha01
when using aView
within aFragment
. (aosp/1297993, aosp/1300264)
API Changes
- The
setFragmentResult()
andsetFragmentResultListener()
APIs now take a non-nullBundle
andFragmentResultListener
, 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()
, andrequestPermissions
onFragment
now 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
illegalStateException
when 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
prepareCall
methods onFragment
are nowfinal
. (b/152439361)
Bug Fixes
- Fixed a regression introduced in Fragment
1.3.0-alpha02
when usingBottomSheetDialogFragment
. (b/151652127, aosp/1263328, aosp/1265163) - Fixed a crash when using
prepareCall
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) - From Fragment
1.2.4
: Updated the Fragment ProGuard rules to allow obfuscation of kept fragments. (b/151605338) - From Fragment
1.2.4
: Disabled theFragmentLiveDataObserve
Lint rule onDialogFragment
classes as their lifecycle and view lifecycle are always in sync, making it safe to use eitherthis
orviewLifecycleOwner
when 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
ActivityResultRegistry
API introduced in Activity1.2.0-alpha02
to 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
DialogFragment
now provides a constructor that takes a@LayoutRes
that 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, aLifeCycleObserver
should be registered on the activity'sLifecycle
inonAttach()
, and removed once theonCreate()
callback is received. (b/144309266)
Bug Fixes
- From Fragment
1.2.3
: Fixed a bug inDialogFragment
that caused aStackOverflowError
when 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 theUseRequireInsteadOfGet
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 anUnsupportedOperationException
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 Lifecycle2.3.0-alpha01
such that it will return the Fragment’sviewLifecycleOwner
as theLifecycleOwner
for 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 theViewModel
and theonCleared()
callback it receives). (b/143911815) - With the release of ViewPager2
1.0.0
, theFragmentPagerAdapter
andFragmentStatePagerAdapter
classes for interacting withViewPager
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 allFragment
instances, fixing a regression introduced in Fragment1.2.1
. (b/149665169 - The
require___()
Lint rules added in Fragment1.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) FragmentContainerView
no longer throws anUnsupportedOperationException
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
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
FragmentLiveDataObserve
Lint rule onDialogFragment
classes as their lifecycle and view lifecycle are always in sync, making it safe to use eitherthis
orviewLifecycleOwner
when 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
DialogFragment
that caused aStackOverflowError
when 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
UseRequireInsteadOfGet
Lint check when using a local variable name that shadowed the Kotlin property name. (b/149891163) FragmentContainerView
no longer throws anUnsupportedOperationException
for 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
viewLifecycleOwner
as theLifecycleOwner
to calls intoOnBackPressedDispatcher
inonCreateView()
,onViewCreated()
, andonActivityCreated()
. (b/142117657) - Added a new Lint check that confirms that you are using the correct
debugImplementation
when using thefragment-testing
artifact. (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 aget
andrequire
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 usingobserve
to also handle thelivedata-ktx
extension 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
add
andreplace
methods that take aClass
instance (or the Kotlin reified versions) now have their default constructor kept by ProGuard. (b/148181315) FragmentStatePagerAdapter
andFragmentPagerAdapter
no longer catch exceptions thrown byFragmentManager
when 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 aFragmentManager
instance no longer throws aNullPointerException
when the Activity is already destroyed. (b/148189412)
Dependency changes
- Fragments
1.2.1
now 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
FragmentContainerView
is the strongly recommended container for dynamically added Fragments, replacing usage ofFrameLayout
or other layouts. It also supports the sameclass
,android:name
, and optionalandroid:tag
as the<fragment>
tag, but uses a normalFragmentTransaction
to 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()
onFragmentTransaction
that take aClass<? extends Fragment>
and optionalBundle
of arguments. These methods use yourFragmentFactory
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 tofragment-ktx
. - Lifecycle ViewModel SavedState Integration:
SavedStateViewModelFactory
is now the default factory used when usingby viewModels()
,by activityViewModels()
, theViewModelProvider
constructor, orViewModelProviders.of()
with a Fragment. - New Lint checks: Added a new Lint check that ensures you are using
getViewLifecycleOwner()
when observingLiveData
fromonCreateView()
,onViewCreated()
, oronActivityCreated()
. getFragmentManager()
deprecation: ThegetFragmentManager()
andrequireFragmentManager()
methods on Fragment have been deprecated and replaced with a singlegetParentFragmentManager()
method, which returns the non-nullFragmentManager
the Fragment is added to (you can useisAdded()
to determine if it is safe to call).FragmentManager.enableDebugLogging()
deprecation: The staticFragmentManager.enableDebugLogging
method has been deprecated. FragmentManager now respectsLog.isLoggable()
for the tagFragmentManager
, allowing you to enable eitherDEBUG
orVERBOSE
logging without re-compiling your app.
Known Issues
- Fragments referenced only via the
class
orandroid:name
attribute on aFragmentContainerView
are not kept by ProGuard automatically, requiring that you manually add a keep rule for each fragment class. (b/142601969) - When adding a
NavHostFragment
usingclass
orandroid:name
in 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-rc04
when 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 toCREATED
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
, andTRANSIT_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) - 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
INVISIBLE
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) - Improved the documentation on
setFragmentFactory()
andgetFragmentFactory()
to better indicate that setting aFragmentFactory
will 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 observingLiveData
fromonCreateView()
,onViewCreated()
, oronActivityCreated()
(introduced in Fragment1.2.0-rc01
) now uses the Kotlin property access syntaxviewLifecycleOwner
instead 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
FragmentContainerView
now supports theclass
attribute 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 observingLiveData
fromonCreateView()
,onViewCreated()
, oronActivityCreated()
. (b/137122478)
Bug fixes
- The
onDismiss
andonCancel
callbacks onDialogFragment
now guarantee that theDialogInterface
passed to them is non-null and thatgetDialog()
returns non-null when they are executed. (b/141974033) FragmentContainerView
now adds the Fragment defined byclass
orandroid:name
as part of inflation, ensuring thatfindFragmentById()
andfindFragmentByTag()
work immediately afterwards. (b/142520327)- Fixed an
IllegalStateException
inFragmentContainerView
due to the state being saved. (b/142580713) - Fixed an
UnsupportedOperationException
inFragmentContainerView
when theFragmentContainerView
class is obfuscated. (b/142657034)
Known issues
- Fragments referenced only via the
class
orandroid:name
attribute on aFragmentContainerView
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 toFragmentContainerView
until 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
FragmentContainerView
adds support for adding an initial fragment with added support for theandroid:name
and optionalandroid:tag
XML attributes. Unlike the<fragment>
tag,FragmentContainerView
uses a normalFragmentTransaction
under the hood to add the initial fragment, allowing furtherFragmentTransaction
operations on theFragmentContainerView
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>
withFragmentContainerView
. (b/139830056)
Bug fixes
- Fixed a
ClassCastException
when usingandroidx.transition
. (b/140680619) - When using Transition
1.3.0-beta01
, Fragments now wait forandroidx.transition
transitions (in addition to framework transitions and animations, which were fixed in Fragment1.2.0-alpha03
and Fragment1.2.0-alpha02
, respectively) to finish before dispatchingonDestroyView()
. (aosp/1119841) - When using Transition
1.3.0-beta01
, Fragments now properly cancelandroidx.transition
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 usingFragmentContainerView
. (b/140361893) - The
fragment-testing
artifact now depends on AndroidX Test1.2.0
, 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 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 onFragment
have been deprecated and replaced with a singlegetParentFragmentManager()
method, which returns the non-nullFragmentManager
the Fragment is added to (you can useisAdded()
to determine if it is safe to call). (b/140574496) - The static
FragmentManager.enableDebugLogging
method has been deprecated. FragmentManager now respectsLog.isLoggable()
for the tagFragmentManager
, allowing you to enable eitherDEBUG
orVERBOSE
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 nowfinal
. (b/140133091)
Bug fixes
FragmentContainerView
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 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
SavedStateViewModelFactory
is now the default factory used when usingby viewModels()
,by activityViewModels()
, theViewModelProvider
constructor, orViewModelProviders.of()
with aFragment
. (b/135716331)- The default animations when using
TRANSIT_FRAGMENT_OPEN
,TRANSIT_FRAGMENT_CLOSE
,TRANSIT_FRAGMENT_FADE
withsetTransition
on aFragmentTransaction
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 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()
onFragmentTransaction
that take aClass<? extends Fragment>
and optionalBundle
of arguments. These methods use yourFragmentFactory
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 tofragment-ktx
. (b/126124987) @MainThread
annotations have been added toFragment
lifecycle callbacks. (b/127272564)- The breadcrumb title related APIs on
FragmentTransaction
andFragmentManager.BackStackEntry
have been deprecated. (b/138252944) - The
setTransitionStyle
method onFragmentTransaction
has been deprecated. (aosp/1011537) - Many of the methods in
FragmentManager
are no longerabstract
.FragmentManager
itself remainsabstract
and 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 inFragmentPagerAdapter
andFragmentStatePagerAdapter
when 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
NullPointerException
when using shared element transitions and combining a pop and add operation. (b/120507394) - Added a workaround to
IllegalStateException
s when usingFragmentPagerAdapter
andFragmentStatePagerAdapter
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 callingonViewCreated()
, ensuring that your view always has the correct insets. (b/135945162)
Bug fixes
- Fixed a
NullPointerException
when popping aFragmentTransaction
that 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-testing
artifact provides aFragmentScenario
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 aFragmentManager
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 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()
.FragmentPagerAdapter
andFragmentStatePagerAdapter
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 onFragmentActivity
that takes anR.layout
ID, 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
Fragment
can now optionally call into a constructor onFragment
that takes anR.layout
ID, 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
FragmentPagerAdapter
andFragmentStatePagerAdapter
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()
orhide()
operations while the transition is running. (b/133385058) - Fixed a
NullPointerException
when popping aFragmentTransaction
that 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.Lifecycle
callbacks (specifically related toSTARTED
,RESUMED
,PAUSED
,STOPPED
, andDESTROYED
) for nested Fragments are now properly nested. (b/133497591)OnBackPressedCallback
instances 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
FragmentFactory
instantiate
method that took aBundle
has been removed. aosp/953856 - Breaking change: The
RESUME_ONLY_CURRENT_FRAGMENT
andUSE_SET_USER_VISIBLE_HINT
constants inFragmentPagerAdapter
andFragmentStatePagerAdapter
have been renamed toBEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
andBEHAVIOR_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()
.FragmentPagerAdapter
andFragmentStatePagerAdapter
have a new constructor that allows you to switch to the new behavior. (b/129780800)
API Changes
moveToState(STARTED)
onFragmentScenario
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 thecontentLayoutId
constructor ofFragmentActivity
orAppCompatActivity
. (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) - Fixed a crash in
restoreSaveState
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 theFragmentManager
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
andFragmentActivity
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)- FragmentActivity’s
onActivityResult()
is now properly marked as@CallSuper
. (b/127971684) - The FragmentFactory’s
instantiate
method that takes an argument Bundle has been deprecated and apps should use the newinstantiate
overload that does not take a Bundle. (b/128836103) FragmentScenario
methods are now properly annotated with@StyleRes
. (aosp/924193)FragmentTabHost
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) - 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()
, andsetPrimaryNavigationFragment()
with a Fragment attached to a different FragmentManager now throws anIllegalStateException
rather than silently failing (aosp/904301)
Bug fixes
onNewIntent
forFragmentActivity
is 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
@ContentView
class 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-testing
now depends onandroidx.test:core-ktx
1.1.0 stable (b/121209673)- You can now use
openActionBarOverflowOrOptionsMenu
withFragmentScenario
to test Fragment hosted options menus (b/121126668)
API changes
- Added a
requireArguments()
method which returns a@NonNull Bundle
or 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
null
tosetTargetFragment()
. (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
BundleSavedStateRegistryOwner
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] - The
by viewModels
Kotlin property delegate has been expanded to take an optional lambda method for getting theViewModelStoreOwner
, allowing you to pass in the parent Fragment or other customViewModelStoreOwner
with code such asval viewModel: MyViewModel by viewModels(::requireParentFragment)
[b/119050253]
API changes
FragmentScenario
now allows you to specify a theme such asTheme.AppCompat
[b/119054431]. This is a breaking change.- Added a
requireView()
method which returns a@NonNull View
or throws anIllegalStateException
[b/120241368] - Added a
requireParentFragment()
method which returns a@NonNull Fragment
or 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
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 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
FragmentFactory
on anyFragmentManager
to 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-testing
depends onandroidx.test:core:1.0.0-beta01
instead of the correctandroidx.test:core:1.0.0
.