Register now for Android Dev Summit 2019!

Fragment

Version 1.1.0-rc03

July 19, 2019

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

Bug fixes

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

Version 1.1.0-rc02

July 17, 2019

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

Bug fixes

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

Version 1.2.0-alpha01

July 2, 2019

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

New features

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

Bug fixes

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

Version 1.1.0-rc01

July 2, 2019

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

Bug fixes

  • Fragments now properly update their visibility when using show() or hide() operations while the transition is running. (b/133385058)
  • Fixed a NullPointerException when popping a FragmentTransaction that used setPrimaryNavigationFragment() before replace(). (b/134673465)

Version 1.1.0-beta01

June 5, 2019

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

Bug fixes

  • androidx.lifecycle.Lifecycle callbacks (specifically related to STARTED, RESUMED, PAUSED, STOPPED, and DESTROYED) for nested Fragments are now properly nested. (b/133497591)
  • OnBackPressedCallback instances registered in a Fragment’s onCreate() now properly take precedence over the child FragmentManager. (b/133175997)
  • Child fragments are no longer animated when their parent fragment is being replaced. (b/121017790)
  • Fragments animations and transitions are now ignored when using animateLayoutChanges="true", fixing an issue where Fragments were not properly destroyed. (b/116257087)

Version 1.1.0-alpha09

May 16, 2019

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

API changes

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

Bug fixes

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

Version 1.1.0-alpha08

May 7, 2019

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

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

New features

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

API changes

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

Bug fixes

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

Version 1.1.0-alpha07

April 25, 2019

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

New features

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

API Changes

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

Behavior Changes

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

Bug fixes

  • Fixed an issue when using a <fragment> tag in XML and the contentLayoutId constructor of FragmentActivity or AppCompatActivity. (b/129907905)
  • 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 the FragmentManager had a back stack. See androidx.activity 1.0.0-alpha07 for more details. (aosp/948209)
  • Fragments no longer enforce LAYER_TYPE_HARDWARE for animations. If you specifically need a hardware layer animation, please set it as part of your animation. (b/129486478)

Version 1.1.0-alpha06

April 3, 2019

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

New features

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

API Changes

  • Fragment and FragmentActivity now contain a second constructor that takes a @LayoutRes int, which replaces the previous behavior of annotating your class with @ContentView. This approach works in both app and library modules. (b/128352521)
  • 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 new instantiate 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(), and setPrimaryNavigationFragment() with a Fragment attached to a different FragmentManager now throws an IllegalStateException rather than silently failing (aosp/904301)

Bug fixes

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

Version 1.1.0-alpha04

February 7, 2019

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

New features

  • Added support for the @ContentView class annotation that allows you to indicate which layout XML file should be inflated as an alternative to overriding onCreateView(). It is recommended to do view related work in onViewCreated(). (aosp/837619)
  • fragment-testing now depends on androidx.test:core-ktx 1.1.0 stable (b/121209673)
  • You can now use openActionBarOverflowOrOptionsMenu with FragmentScenario to test Fragment hosted options menus (b/121126668)

API changes

  • Added a requireArguments() method which returns a @NonNull Bundle or throws an IllegalStateException (b/121196360)
  • Added a note that getLifecycle(), getViewLifecycleOwner(), and getViewLifecycleOwnerLiveData() should not be overridden and will be made final in a future release. Please file a feature request if you are currently overriding this method. (aosp/880714)
  • 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 to setTargetFragment(). (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 the ViewModelStoreOwner, allowing you to pass in the parent Fragment or other custom ViewModelStoreOwner with code such as val viewModel: MyViewModel by viewModels(::requireParentFragment) [b/119050253]

API changes

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

Bug fixes

  • Fixed IllegalStateException: Failure saving state b/120814739
  • Fragments being restored from saved instance state will now always receive a non-null Bundle [b/119794496]
  • Removed Fragments no longer reuse their Lifecycle object if re-added [b/118880674]

Version 1.1.0-alpha02

December 3, 2018

New features

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

Bug fixes

  • Fixed an IllegalStateException when using nested Fragments on the back stack (b/119256498)
  • Fixed crash when using FragmentScenario.recreate() with a FragmentFactory (aosp/820540)
  • Fixed an issue where target Fragments were not accessible after the Fragment was removed (aosp/807634)

Version 1.1.0-alpha01

November 5, 2018

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

New features

  • New FragmentScenario class for testing Fragments in isolation.
  • You can now set a FragmentFactory on any FragmentManager to control how new Fragment instances are instantiated.
  • 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 on androidx.test:core:1.0.0-beta01 instead of the correct androidx.test:core:1.0.0.