Activity
Access composable APIs built on top of Activity.
Latest Update Stable Release Release Candidate Beta Release Alpha Release
October 30, 2024 1.9.3 - - 1.10.0-alpha03

Declaring dependencies

To add a dependency on Activity, 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:

Groovy

dependencies {
    def activity_version = "1.9.3"

    // Java language implementation
    implementation "androidx.activity:activity:$activity_version"
    // Kotlin
    implementation "androidx.activity:activity-ktx:$activity_version"
}

Kotlin

dependencies {
    val activity_version = "1.9.3"

    // Java language implementation
    implementation("androidx.activity:activity:$activity_version")
    // Kotlin
    implementation("androidx.activity:activity-ktx:$activity_version")
}

For more information about dependencies, see Add build dependencies.

Feedback

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

Create a new issue

See the Issue Tracker documentation for more information.

Version 1.10

Version 1.10.0-alpha03

October 30, 2024

androidx.activity:activity:1.10.0-alpha03, androidx.activity:activity-compose:1.10.0-alpha03, and androidx.activity:activity-ktx:1.10.0-alpha03 are released. Version 1.10.0-alpha03 contains these commits.

API Changes

  • Added a new LocalActivity composition local that provides the Activity for the current scope, removing the need for developers to get an Activity from the LocalContext. It also comes with a new lint rule that checks when the LocalContext is incorrectly being cast to an Activity. (I7746a, b/283009666)

Bug Fixes

  • From Activity 1.9.3: PredictiveBackHandler will no longer fire it's callback after the handler has been disabled. This will fix an issue where the NavHost from Navigation Compose would throw an IndexOutOfBoundsException. (I3f75e, b/365027664, b/340202286)

Dependency Update

Version 1.10.0-alpha02

September 4, 2024

androidx.activity:activity:1.10.0-alpha02, androidx.activity:activity-compose:1.10.0-alpha02, and androidx.activity:activity-ktx:1.10.0-alpha02 are released. Version 1.10.0-alpha02 contains these commits.

Behavior Changes

  • The PickVisualMedia and PickMultipleVisualMedia Activity Result contracts that trigger the Photo Picker no longer directly delegates to Google Play services if the system Photo picker is not available, but uses the public ACTION_SYSTEM_FALLBACK_PICK_IMAGES action and related extras to provide a consistent Photo Picker experience to OEMs and system apps as a fallback. This should have no effect on the user experience for devices that have a recent version of Google Play services. (I3513d)

Bug Fixes

  • Removed manual outlining of access to new platform APIs since this happens automatically via API modeling when using R8 with AGP 7.3 or later (e.g. R8 version 3.3) and for all builds when using AGP 8.1 or later (e.g. D8 version 8.1). Clients who are not using AGP are advised to update to D8 version 8.1 or later. See this article for more details. (I9496c, b/345472586)
  • From Activity 1.9.2: Fixed an issue where the Activity Compose PredictiveBackHandler API would continue to handle the system back gesture on the frame it was disabled, which could result in libraries like Navigation Compose to handle back even with an empty back stack, resulting in it throwing an IndexOutOfBoundsException. (Ie3301, b/340202286)
  • From Activity 1.9.1: Fixed an issue with PredictiveBackHandler where after doing system back, attempting to do onBackPressed from the OnBackPressedDispatcher would fail. (I5f1f8)

Version 1.10.0-alpha01

June 26, 2024

androidx.activity:activity:1.10.0-alpha01, androidx.activity:activity-compose:1.10.0-alpha01, and androidx.activity:activity-ktx:1.10.0-alpha01 are released. This version is developed in an internal branch.

New Features

  • Added support for new PhotoPicker features introduced in Android V including being able to pick images in order and choose which tab (either albums or images) should be initially visible.

Version 1.9

Version 1.9.3

October 16, 2024

androidx.activity:activity:1.9.3, androidx.activity:activity-compose:1.9.3, and androidx.activity:activity-ktx:1.9.3 are released. Version 1.9.3 contains these commits.

Bug Fixes

  • PredictiveBackHandler will no longer fire it's callback after the handler has been disabled. This will fix an issue where the NavHost from Navigation Compose would throw an IndexOutOfBoundsException. (I3f75e, b/340202286)

Version 1.9.2

September 4, 2024

androidx.activity:activity:1.9.2, androidx.activity:activity-compose:1.9.2, and androidx.activity:activity-ktx:1.9.2 are released. Version 1.9.2 contains these lthcocommits.

Bug Fixes

  • Fixed an issue where the Activity Compose PredictiveBackHandler API would continue to handle the system back gesture on the frame it was disabled, which could result in libraries like Navigation Compose to handle back even with an empty back stack, resulting in it throwing an IndexOutOfBoundsException. (Ie3301, b/340202286)

Version 1.9.1

July 24, 2024

androidx.activity:activity:1.9.1, androidx.activity:activity-compose:1.9.1, and androidx.activity:activity-ktx:1.9.1 are released. Version 1.9.1 contains these commits.

Bug Fixes

  • Fixed an issue with PredictiveBackHandler where after doing system back, attempting to do onBackPressed from the OnBackPressedDispatcher would fail. (I5f1f8)

Version 1.9.0

April 17, 2024

androidx.activity:activity:1.9.0, androidx.activity:activity-compose:1.9.0, and androidx.activity:activity-ktx:1.9.0 are released. Version 1.9.0 contains these commits.

Important changes since 1.8.0

  • ComponentActivity now implements OnUserLeaveHintProvider to allow components to callbacks for onUserLeaveHint events.
  • The OnBackPressedCallback, BackHandler, and PredictiveBackHandler APIs now warn when calling onBackPressedDispatcher.onBackPressed() when handling back as that will always break the Predictive Back Animation. See the best practices guide for more details.
  • The remainder of the Activity APIs have been rewritten in Kotlin and all extensions previously available in activity-ktx have been moved to activity. activity-ktx is now completely empty.
    • As part of the conversion of ActivityResultLauncher to Kotlin, the getContract method is now an abstract Kotlin property. This is a binary compatible change, but source breaking if your implementation of ActivityResultLauncher is written in Kotlin.

Version 1.9.0-rc01

April 3, 2024

androidx.activity:activity:1.9.0-rc01, androidx.activity:activity-compose:1.9.0-rc01, and androidx.activity:activity-ktx:1.9.0-rc01 are released. Version 1.9.0-rc01 contains these commits.

Dependency update

Version 1.9.0-beta01

March 20, 2024

androidx.activity:activity:1.9.0-beta01, androidx.activity:activity-compose:1.9.0-beta01, and androidx.activity:activity-ktx:1.9.0-beta01 are released. Version 1.9.0-beta01 contains these commits.

Bug Fixes

  • Fixed an Activity startup performance regression introduced in Activity 1.9.0-alpha02 caused by calling the OnBackPressedDispatcher as part of the creation of the Activity. (Ie75e3)

Version 1.9.0-alpha03

February 7, 2024

androidx.activity:activity:1.9.0-alpha03, androidx.activity:activity-compose:1.9.0-alpha03, and androidx.activity:activity-ktx:1.9.0-alpha03 are released. Version 1.9.0-alpha03 contains these commits.

Lint Warning

Bug Fixes

  • If a back event is sent from the system started during an already running Predictive Back Gesture, the currently running Predictive Back Gesture is canceled and the new back event takes over to begin a new Predictive Back Gesture. (I3482e)
  • Fixed a crash when accessing the onBackPressedDispatcher from a ComponentActivity for the first time from a background thread. It is now safe to access the onBackPressedDispatcher on any thread. (I79955)

Version 1.9.0-alpha02

January 24, 2024

androidx.activity:activity:1.9.0-alpha02, androidx.activity:activity-compose:1.9.0-alpha02, and androidx.activity:activity-ktx:1.9.0-alpha02 are released. Version 1.9.0-alpha02 contains these commits.

Kotlin Conversions

  • ActivityResultRegistry has been rewritten in Kotlin. This ensures that the nullability of the generics on the contract passed to register will correctly be passed through to the ActivityResultLauncher returned to you. (I121f0)
  • ActivityResult has been rewritten in Kotlin. The ActivityResult Kotlin extensions that support destructuring into the resultCode and data fields have been moved from activity-ktx to activity. (I0565a)
  • The Kotlin extensions of by viewModels() for ComponentActivity and trackPipAnimationHintView have been moved from activity-ktx to activity. The activity-ktx artifact is now completely empty. (I0a444)

Bug Fixes

  • The enableEdgeToEdge API now draws around any display cutouts. (a3644b, b/311173461)
  • From Activity 1.8.2: Fixed the extra passed to the Photo Picker Activity Contract's ACTION_SYSTEM_FALLBACK_PICK_IMAGES to correctly pass it the EXTRA_SYSTEM_FALLBACK_PICK_IMAGES_MAX key, rather than using the extra with the key "com.google.android.gms.provider.extra.PICK_IMAGES_MAX". It is strongly recommended if you are an OEM who implements a system fallback Photo Picker to support both extras to ensure the widest compatibility. (I96a00)

Version 1.9.0-alpha01

November 29, 2023

androidx.activity:activity:1.9.0-alpha01, androidx.activity:activity-compose:1.9.0-alpha01, and androidx.activity:activity-ktx:1.9.0-alpha01 are released. Version 1.9.0-alpha01 contains these commits.

New Features

  • ComponentActivity now implements OnUserLeaveHintProvider to allow components to callbacks for onUserLeaveHint events. (I54892)

API Changes

  • ComponentActivity has been rewritten in Kotlin. (I14f31)
  • ActivityResultCaller has been rewritten in Kotlin. (Ib02e4)
  • ActivityResultLauncher has been rewritten in Kotlin. As part of that conversion, the getContract method is now an abstract Kotlin property. This is a binary compatible change, but source breaking if your implementation of ActivityResultLauncher is written in Kotlin. (Id4615)
  • PickVisualMediaRequest now has the same minimum API level of 19 as the PickVisualMedia Activity Result contract. (Id6e21)

Dependency Update

Version 1.8

Version 1.8.2

December 13, 2023

androidx.activity:activity:1.8.2, androidx.activity:activity-compose:1.8.2, and androidx.activity:activity-ktx:1.8.2 are released. Version 1.8.2 contains these commits.

Bug Fixes

  • Fixed the extra passed to the Photo Picker Activity Contract's ACTION_SYSTEM_FALLBACK_PICK_IMAGES to correctly pass it the EXTRA_SYSTEM_FALLBACK_PICK_IMAGES_MAX key, rather than using the extra with the key "com.google.android.gms.provider.extra.PICK_IMAGES_MAX". It is strongly recommended if you are an OEM who implements a system fallback Photo Picker to support both extras to ensure the widest compatibility. (I96a00)

Version 1.8.1

November 15, 2023

androidx.activity:activity:1.8.1, androidx.activity:activity-compose:1.8.1, and androidx.activity:activity-ktx:1.8.1 are released. Version 1.8.1 contains these commits.

Bug Fixes

  • OnBackPressedDispatcher now continues to dispatch to the correct OnBackPressedCallback even after a new OnBackPressedCallback is added while the back gesture is being handled. (Id0ff6)

Version 1.8.0

October 4, 2023

androidx.activity:activity:1.8.0, androidx.activity:activity-compose:1.8.0, and androidx.activity:activity-ktx:1.8.0 are released. Version 1.8.0 contains these commits.

Important changes since 1.7.0

  • Predictive Back - The OnBackPressedCallback now offers new Predictive Back callbacks for handling the back gesture starting, progress throughout the gesture, and the back gesture being canceled in addition to the previous handleOnBackPressed() callback for when the back gesture is committed. This also comes with the PredictiveBackHandler Composable to handle predictive back gesture events in Activity Compose. It provides a Flow of BackEventCompat objects that must be collected in the suspending lamba you provide:
  PredictiveBackHandler { progress: Flow<BackEventCompat> ->
    // code for gesture back started
    try {
      progress.collect { backEvent ->
      // code for progress
    }
    // code for completion
    } catch (e: CancellationException) {
      // code for cancellation
    }
  }

ComponentActivity.onBackPressed() has now been deprecated in favor of the APIs for handling back. Developers should now utilize the OnBackPressedDispatcher, rather than overriding this method.

  • EdgeToEdge - ComponentActivity.enableEdgeToEdge() has been added to easily set up the edge-to-edge display in a backward-compatible manner.

Version 1.8.0-rc01

September 20, 2023

androidx.activity:activity:1.8.0-rc01, androidx.activity:activity-compose:1.8.0-rc01, and androidx.activity:activity-ktx:1.8.0-rc01 are released. Version 1.8.0-rc01 contains these commits.

Version 1.8.0-beta01

September 6, 2023

androidx.activity:activity:1.8.0-beta01, androidx.activity:activity-compose:1.8.0-beta01, and androidx.activity:activity-ktx:1.8.0-beta01 are released. Version 1.8.0-beta01 contains these commits.

Documentation Improvement

  • Improved the documentation of BackEventCompat. (aosp/2722254)

Version 1.8.0-alpha07

August 23, 2023

androidx.activity:activity:1.8.0-alpha07, androidx.activity:activity-compose:1.8.0-alpha07, and androidx.activity:activity-ktx:1.8.0-alpha07 are released. Version 1.8.0-alpha07 contains these commits.

New Features

  • Activity Compose has added a new PredictiveBackHandler Composable to handle predictive back gesture events. It provides a Flow of BackEventCompat objects that must be collected in the suspending lamba you provide:

    PredictiveBackHandler { progress: Flow<BackEventCompat> ->
      // code for gesture back started
      try {
        progress.collect { backEvent ->
        // code for progress
      }
      // code for completion
      } catch (e: CancellationException) {
        // code for cancellation
      }
    }
    

    It also comes with a compile time warning via lint rule to ensure the Flow calls collect(). (Id2773, b/294884345)

  • The onBackPressedDispatcher in ComponentActivity is now initialized lazily so that it is only created when required. (I0bf8e)

Bug Fixes

  • ComponentActivity will no longer show a NPE on Android 13 when it gets an onBackPressed() callback and the Activity has already been DESTROYED. (Idb055, b/291869278)
  • Removed usages of experimental isAtLeastU() API (Ie9117, b/289269026)

Version 1.8.0-alpha06

June 21, 2023

androidx.activity:activity:1.8.0-alpha06, androidx.activity:activity-compose:1.8.0-alpha06, and androidx.activity:activity-ktx:1.8.0-alpha06 are released. Version 1.8.0-alpha06 contains these commits.

New Features

  • The OnBackPressedDispatcher now correctly cancels any callbacks that are removed during a Predictive Back Gesture. (I3f90f)

API Changes

  • When passing SystemBarStyle.auto to the enableEdgeToEdge API, you can now override the detectDarkMode lambda parameter to provide custom logic for detecting night mode. (aosp/2546393, b/278263793)

Version 1.8.0-alpha05

June 7, 2023

androidx.activity:activity:1.8.0-alpha05, androidx.activity:activity-compose:1.8.0-alpha05, and androidx.activity:activity-ktx:1.8.0-alpha05 are released. This version is developed in an internal branch.

API Changes

  • Activity now provides a BackEventCompat class that serves as a backward compatible version of BackEvent that is decoupled from the framework BackEvent class.
  • Breaking change: The handleOnBackStarted and handleOnBackProgressed methods of OnBackPressedCallback now receive an androidx.activity.BackEventCompat instance rather than a framework android.window.BackEvent class. The equivalent @VisibleForTesting APIs on OnBackPressedDispatcher have also been updated.
  • The constructor for OnBackPressedDispatcher now takes an optional Consumer<Boolean> instance that allows the owners of the dispatcher to receive a callback whenever the number of enabled callbacks changes from zero to non-zero or vice versa.

Bug Fixes

Version 1.8.0-alpha04

May 10, 2023

androidx.activity:activity:1.8.0-alpha04, androidx.activity:activity-compose:1.8.0-alpha04, and androidx.activity:activity-ktx:1.8.0-alpha04 are released. This was released from an internal branch.

Bug Fixes

Version 1.8.0-alpha03

April 12, 2023

androidx.activity:activity:1.8.0-alpha03, androidx.activity:activity-compose:1.8.0-alpha03, and androidx.activity:activity-ktx:1.8.0-alpha03 are released. This was released from an internal branch.

New Features

  • Added ComponentActivity.setUpEdgeToEdge() to easily set up the edge-to-edge display in a backward-compatible manner.

API Changes

  • ComponentActivity.onBackPressed() has now been deprecated in favor of the APIs for handling back. Developers should now utilize the OnBackPressedDispatcher, rather than overriding this method. (Ibce2f, b/271596918)
  • ComponentDialog and ComponentActivity now contain public API initViewTreeOwners() to be used to initialize all view tree owners before setting the content view. (Ibdce0, b/261314581)

Bug Fixes

  • Fixed an issue where Fragments were incorrectly invalidating MenuHosts and causing other menus in the Activity to have unexpected behavior. (I9404e, b/244336571)

Other Changes

  • The ActivityResultRegister now uses Kotlin Random instead of Java. (I4d98f, b/272096025)

Version 1.8.0-alpha02

March 8, 2023

androidx.activity:activity:1.8.0-alpha02, androidx.activity:activity-compose:1.8.0-alpha02, and androidx.activity:activity-ktx:1.8.0-alpha02 are released. Developed from an internal branch.

Dependency update

Version 1.8.0-alpha01

February 8, 2023

androidx.activity:activity:1.8.0-alpha01, androidx.activity:activity-compose:1.8.0-alpha01, and androidx.activity:activity-ktx:1.8.0-alpha01 are released. This was built from an internal branch.

New Features

  • The OnBackPressedCallback class now contains new Predictive Back progress callbacks for handling the back gesture starting, progress throughout the gesture, and the back gesture being canceled in addition to the previous handleOnBackPressed() callback for when the back gesture is committed.

Version 1.7

Version 1.7.2

May 24, 2023

androidx.activity:activity:1.7.2, androidx.activity:activity-compose:1.7.2, and androidx.activity:activity-ktx:1.7.2 are released. Version 1.7.2 contains these commits.

Bug Fixes

  • Fix ReportDrawn crashing when navigating away from a screen before report is called. (Ic46f1, b/260506820)

Version 1.7.1

April 19, 2023

androidx.activity:activity:1.7.1, androidx.activity:activity-compose:1.7.1, and androidx.activity:activity-ktx:1.7.1 are released. Version 1.7.1 contains these commits.

Bug Fixes

  • The ReportFullyDrawExecuter no longer leaks when using ComponentActivity with ActivityScenario. (Id2ff2, b/277434271)

Version 1.7.0

March 22, 2023

androidx.activity:activity:1.7.0, androidx.activity:activity-compose:1.7.0, and androidx.activity:activity-ktx:1.7.0 are released. Version 1.7.0 contains these commits.

Important changes since 1.6.0

  • The Photo Picker activity contracts in PickVisualMedia and PickMultipleVisualMedia have been updated to contain an additional fallback for when MediaStore.ACTION_PICK_IMAGES is unavailable that allows OEMs and system apps, such as Google Play services, to provide a consistent Photo Picker experience on a wider range of Android devices and API levels by implementing the fallback action. The Photo Picker will use this fallback if it is available before falling back to using Intent.ACTION_OPEN_DOCUMENT, which remains to support all API 19 and higher devices.
  • ComponentDialog now implements SavedStateRegistryOwner and has access to its own SavedStateRegistry and sets the SavedStateRegistryOwner for its ViewTree. It is now possible to use Jetpack Compose within a ComponentDialog as it meets both the LifecycleOwner and SavedStateRegistryOwner attached to the Window via the ViewTree APIs requirements.
  • IntentSenderRequest.Builder.setFlags() now allows you to set multiple flags from Intent, rather than only a single flag.

Kotlin Conversion

A number of Activity classes have been converted to Kotlin. All converted classes still retain their binary compatibility with previous versions. The following classes have source incompatible changes for classes written in Kotlin: ActivityResultRegistryOwner, OnBackPressedDispatcherOwner.

The table below provides the source conversions for the new version of Activity:

Activity 1.5 Activity 1.6
override fun getActivityResultRegistry() = activityResultRegistry override val activityResultRegistry = activityResultRegistry
override fun getOnBackPressedDispatcher() = onBackPressedDispatcher override val >

These classes were also converted to Kotlin, but remain source compatible: ContextAware, ContextAwareHelper, OnContextAvailableListener, IntentSenderRequest, and OnBackPressedDispatcher

FullyDrawnReporter APIs

ComponentActivity now provides a FullyDrawnReporter instance that allows multiple components to report when they are ready for interaction. ComponentActivity will wait for all components to complete before calling reportFullyDrawn() on your behalf. These APIs take care of the timing requirements for you and do not need to be called as part of an onDraw call.

These APIs are encouraged to enable:

  • Signaling the Android Runtime when startup completes, to ensure all of the code run during a multi-frame startup sequence is included and prioritized for background compilation.
  • Signaling Macrobenchmark and Play Vitals when your application should be considered fully drawn for startup metrics, so you can track performance.

Three Activity Compose APIs have been added to make it more convenient to use the FullyDrawnReporter from individual composables:

  • ReportDrawn indicates that your composable is immediately ready for interaction.
  • ReportDrawnWhen takes a predicate (i.e., list.count > 0) to indicate when your composable is ready for interaction.
  • ReportDrawnAfter takes a suspending method that, when it completes, indicates that you are ready for interaction.

Dependency Updates

Version 1.7.0-rc01

March 8, 2023

androidx.activity:activity:1.7.0-rc01, androidx.activity:activity-compose:1.7.0-rc01, and androidx.activity:activity-ktx:1.7.0-rc01 are released. Version 1.7.0-rc01 contains these commits.

Dependency update

Version 1.7.0-beta02

February 22, 2023

androidx.activity:activity:1.7.0-beta02, androidx.activity:activity-compose:1.7.0-beta02, and androidx.activity:activity-ktx:1.7.0-beta02 are released. Version 1.7.0-beta02 contains these commits.

API Changes

  • The action and extra used by the PickVisualMedia and PickMultipleVisualMedia contracts as a fallback for when MediaStore.ACTION_PICK_IMAGES is unavailable are now public constants that provide API stability to OEMs and system apps that want to provide a consistent Photo Picker experience. The implementation of this fallback is still limited to only system apps. (Icd320)

Version 1.7.0-beta01

February 8, 2023

androidx.activity:activity:1.7.0-beta01, androidx.activity:activity-compose:1.7.0-beta01, and androidx.activity:activity-ktx:1.7.0-beta01 are released. Version 1.7.0-beta01 contains these commits.

New Features

  • IntentSenderRequest.Builder.setFlags() now allows you to set multiple flags from Intent, rather than only a single flag. (Iac04c)

Bug Fixes

  • The fallback for PickVisualMedia for when the framework Photo Picker is unavailable now correctly limits the handling to apps installed in the device's system image. (If8ae6)

Kotlin Conversions

  • ActivityResultRegistryOwner is now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now override the activityResultRegistry property rather than implementing the previous getActivityResultRegistry() function. (I0b00e)
  • OnBackPressedDispatcherOwner is now written in Kotlin. This is a source incompatible change for those classes written in Kotlin - you must now override the onBackPressedDispatcher property rather than implementing the previous getOnBackPressedDispatcher function. (Ia277d)
  • ContextAware, ContextAwareHelper, OnContextAvailableListener, IntentSenderRequest and OnBackPressedDispatcher are now written in Kotlin. (I1a73e, Iada92, aosp/2410754, I18ac7, b/257291701)

Version 1.7.0-alpha04

January 25, 2023

androidx.activity:activity:1.7.0-alpha04, androidx.activity:activity-compose:1.7.0-alpha04, and androidx.activity:activity-ktx:1.7.0-alpha04 are released. Version 1.7.0-alpha04 contains these commits.

New Features

  • The PickVisualMedia and PickMultipleVisualMedia Activity Result contracts will now use a Google Play services provided Photo Picker where available in cases where the Android system provided Photo Picker (e.g., MediaStore.ACTION_PICK_IMAGES) is not available. The isPhotoPickerAvailable() API that only detects the Android system provided Photo Picker has been deprecated. It is recommended to use the new isPhotoPickerAvailable(Context) API, which will return if either Photo Picker is available. (I55be6)

Version 1.7.0-alpha03

January 11, 2023

androidx.activity:activity:1.7.0-alpha03, androidx.activity:activity-compose:1.7.0-alpha03, and androidx.activity:activity-ktx:1.7.0-alpha03 are released. Version 1.7.0-alpha03 contains these commits.

New Features

  • ComponentDialog now implements SavedStateRegistryOwner and has access to its own SavedStateRegistry and sets the SavedStateRegistryOwner for its ViewTree. It is now possible to use Jetpack Compose within a ComponentDialog as it meets both the LifecycleOwner and SavedStateRegistryOwner attached to the Window via the ViewTree APIs requirements. (Idca17, I73468 b/261162296)

API Changes

  • Added a ReportDrawn composable that immediately marks the activity as ready to call reportFullyDrawn. (Ic5b14, b/259687964)

Kotlin Conversions

  • The ActvitiyResultCallback and OnBackPressedCallback classes have both been converted to Kotlin while maintaining source and binary compatibility. (Ifc5e5, Ide1b0, b/257291701)

Version 1.7.0-alpha02

October 24, 2022

androidx.activity:activity:1.7.0-alpha02, androidx.activity:activity-compose:1.7.0-alpha02, and androidx.activity:activity-ktx:1.7.0-alpha02 are released. Version 1.7.0-alpha02 contains these commits.

Bug Fixes

  • From Activity 1.6.1: Fixed an issue with the PickMultipleVisualMedia Activity Result contract not launching on Android R devices when using the default value for maxItems. (Ie2776, b/249182130)

Version 1.7.0-alpha01

October 5, 2022

androidx.activity:activity:1.7.0-alpha01, androidx.activity:activity-compose:1.7.0-alpha01, and androidx.activity:activity-ktx:1.7.0-alpha01 are released. Version 1.7.0-alpha01 contains these commits.

FullyDrawnReporter APIs

ComponentActivity now provides a FullyDrawnReporter instance that allows multiple components to report when they are ready for interaction. ComponentActivity will wait for all components to complete before calling reportFullyDrawn() on your behalf. These APIs take care of the timing requirements for you and do not need to be called as part of an onDraw call.

These APIs are encouraged to enable:

  • Signaling the Android Runtime when startup completes, to ensure all of the code run during a multi-frame startup sequence is included and prioritized for background compilation.
  • Signaling Macrobenchmark and Play Vitals when your application should be considered fully drawn for startup metrics, so you can track performance.

Two Activity Compose APIs have been added to make it more convenient to use the FullyDrawnReporter from individual composables:

  • ReportDrawnWhen takes a predicate (i.e., list.count > 0) to indicate when your composable is ready for interaction.
  • ReportDrawnAfter takes a suspending method that, when it completes, indicates that you are ready for interaction.

Version 1.6.1

Version 1.6.1

October 24, 2022

androidx.activity:activity:1.6.1, androidx.activity:activity-compose:1.6.1, and androidx.activity:activity-ktx:1.6.1 are released. Version 1.6.1 contains these commits.

Bug Fixes

  • Fixed an issue with the PickMultipleVisualMedia Activity Result contract not launching on Android R devices when using the default value for maxItems. (Ie2776, b/249182130)

Version 1.6.0

Version 1.6.0

September 21, 2022

androidx.activity:activity:1.6.0, androidx.activity:activity-compose:1.6.0, and androidx.activity:activity-ktx:1.6.0 are released. Version 1.6.0 contains these commits.

Important changes since 1.5.0

  • Added ActivityResultContracts.PickVisualMedia and ActivityResultContracts.PickMultipleVisualMedia for providing a backward compatible contract that uses MediaStore.ACTION_PICK_IMAGES when the Photo Picker is available and Intent.ACTION_OPEN_DOCUMENT when it is not available.
  • Integrated the OnBackInvokedCallback in Android 13 into the OnBackPressedDispatchers provided by ComponentActivity and ComponentDialog. This ensures that all APIs built onOnBackPressedDispatcher work when enabling a predictive back gesture.

Version 1.6.0-rc02

September 7, 2022

androidx.activity:activity:1.6.0-rc02, androidx.activity:activity-compose:1.6.0-rc02, and androidx.activity:activity-ktx:1.6.0-rc02 are released. Version 1.6.0-rc02 contains these commits.

Bug Fixes

  • OnBackPressedDispatcher now registers the OnBackInvokedCallback with the PRIORITY_DEFAULT instead of PRIORITY_OVERLAY. (I3901f)
  • Classes that extend ComponentActivity will now always have both of their onMultiWindowModeChanged() callbacks dispatched. (Ic4d85)
  • The ActivityResultRegistry will no longer return a result to the ActivityResultCallback when the launch call throws any Exception and the callback was registered without a LifecycleOwner. (Ia7ff7, b/238350794)
  • ComponentActivity will now properly dispatch menu calls without the need to call the super function in your activity. (Ie33c5, b/238057118)

Dependency Update

Version 1.6.0-rc01

August 24, 2022

androidx.activity:activity:1.6.0-rc01, androidx.activity:activity-compose:1.6.0-rc01, and androidx.activity:activity-ktx:1.6.0-rc01 are released. Version 1.6.0-rc01 contains these commits.

Bug Fixes

  • Initializing an OnBackPressedDispatcher will no longer cause ClassVerificationErrors when using SDK versions prior to 33. (Ic32e1)
  • Classes that override ComponentActivity’s onPictureInPictureModeChanged() callback will now always have their callbacks dispatched. (Ib7fdb)

Version 1.6.0-beta01

August 10, 2022

androidx.activity:activity:1.6.0-beta01, androidx.activity:activity-compose:1.6.0-beta01, and androidx.activity:activity-ktx:1.6.0-beta01 are released. Version 1.6.0-beta01 contains these commits.

API Changes

  • Marked the deprecated startActivityForResult and startIntentSenderForResult methods on ComponentActivity with @NonNull because passing null has always resulted in a crash. (Id2a25, b/231476082)

Bug Fixes

  • From Activity 1.5.1: The ActivityResultRegistry will no longer return a result to the ActivityResultCallback when the launch call throws any Exception and the callback was registered without a LifecycleOwner. (Ia7ff7, b/238350794)
  • From Activity 1.5.1: ComponentActivity will now properly dispatch menu calls to onPrepareOptionMenu(), onCreateOptionsMenu() and onOptionsItemSelected() overrides without the need to call the super function. (Ie33c5, b/238057118)

Dependency Update

Version 1.6.0-alpha05

June 15, 2022

androidx.activity:activity:1.6.0-alpha05, androidx.activity:activity-compose:1.6.0-alpha05, and androidx.activity:activity-ktx:1.6.0-alpha05 are released. Version 1.6.0-alpha05 was developed in a private pre-release branch and has no public commits.

API Changes

  • minCompileSdk is now 33 to align with Tiramisu Beta 3 SDK

Bug Fixes

  • Fixed crash on older devices when doing SDK extension check for the PickVisualMedia ActivityResultContract so that it should now work with ACTION_OPEN_DOCUMENT on devices running Android 10 and lower.

Version 1.6.0-alpha04

May 18, 2022

androidx.activity:activity:1.6.0-alpha04 and androidx.activity:activity-ktx:1.6.0-alpha04 are released.

Bug Fixes

  • Fixed an error in PickVisualMediaRequest where attempting to create a request, either via the Builder or the top level Kotlin function, would result in a stack overflow.
  • Integrated the OnBackInvokedCallback in Android 13 Dev Beta 2 into the OnBackPressedDispatcher provided by ComponentDialog. This ensures that all APIs built on OnBackPressedDispatcher work when enabling a predictive back gesture.

Version 1.6.0-alpha03

April 27, 2022

androidx.activity:activity:1.6.0-alpha03, androidx.activity:activity-compose:1.6.0-alpha03, and androidx.activity:activity-ktx:1.6.0-alpha03 are released.

  • Note: This version will only compile against the Android 13 Developer Beta 1 SDK.

New Features

  • Added ActivityResultContracts.PickVisualMedia and ActivityResultContracts.PickMultipleVisualMedia for providing a backward compatible contract that uses MediaStore.ACTION_PICK_IMAGES when the Photo Picker is available and Intent.ACTION_OPEN_DOCUMENT when it is not available.
  • Integrated the OnBackInvokedCallback in Android 13 Dev Beta 1 into the OnBackPressedDispatcher provided by ComponentActivity. This ensures that all APIs built on OnBackPressedDispatcher work when enabling a predictive back gesture.

Version 1.6.0-alpha01

March 23, 2022

androidx.activity:activity:1.6.0-alpha01, androidx.activity:activity-compose:1.6.0-alpha01, and androidx.activity:activity-ktx:1.6.0-alpha01 are released.

  • Note: This version will only compile against the Android 13 Developer Preview 2 SDK.

New Features

  • Integrated changes in Android 13 Dev Preview 2 into ComponentActivity.

Version 1.5.1

Version 1.5.1

July 27, 2022

androidx.activity:activity:1.5.1, androidx.activity:activity-compose:1.5.1, and androidx.activity:activity-ktx:1.5.1 are released. Version 1.5.1 contains these commits.

Bug Fixes

  • The ActivityResultRegistry will no longer return a result to the ActivityResultCallback when the launch() call throws any Exception and the callback was registered without a LifecycleOwner. (Ia7ff7, b/238350794)

  • ComponentActivity will now properly dispatch menu calls to onPrepareOptionMenu(), onCreateOptionsMenu() and onOptionsItemSelected() overrides without the need to call the super function. (Ie33c5, b/238057118)

Dependency update

Version 1.5.0

Version 1.5.0

June 29, 2022

androidx.activity:activity:1.5.0, androidx.activity:activity-compose:1.5.0, and androidx.activity:activity-ktx:1.5.0 are released. Version 1.5.0 contains these commits.

Important changes since 1.4.0

  • ComponentDialog - ComponentDialog is a subclass of Dialog that includes an OnBackPressedDispatcher that will be called when the system back button is pressed and the dialog is visible. Importantly, this subclass also sets the ViewTreeOnBackPressedDispatcherOwner, allowing views a generic way to retrieve the correct dispatcher whether it exists in a ComponentActivity or a ComponentDialog.
  • Callback Interfaces - ComponentActivity now implements a set of modular callback interfaces that can be used instead of the Activity callbacks. These interfaces include the following: OnNewIntentProvider, OnConfigurationChangedProvider, OnTrimMemoryProvider, OnPictureInPictureModeChangedProvider, OnMultiWindowModeChangedProvider
  • CreationExtras Integration - ComponentActivity now has the ability to provide a stateless ViewModelProvider.Factory via Lifecycle 2.5.0’s CreationExtras.

Other changes

  • The no parameter constructor for ActivityResultContracts.CreateDocument has been deprecated and replaced with a new constructor that takes a concrete mime type (e.g., "image/png") as is required by Intent.ACTION_CREATE_DOCUMENT.

Version 1.5.0-rc01

May 11, 2022

androidx.activity:activity:1.5.0-rc01, androidx.activity:activity-compose:1.5.0-rc01, and androidx.activity:activity-ktx:1.5.0-rc01 are released with no changes from 1.5.0-beta01. Version 1.5.0-rc01 contains these commits.

Version 1.5.0-beta01

April 20, 2022

androidx.activity:activity:1.5.0-beta01, androidx.activity:activity-compose:1.5.0-beta01, and androidx.activity:activity-ktx:1.5.0-beta01 are released. Version 1.5.0-beta01 contains these commits.

Dependency updates

Version 1.5.0-alpha05

April 6, 2022

androidx.activity:activity:1.5.0-alpha05, androidx.activity:activity-compose:1.5.0-alpha05, and androidx.activity:activity-ktx:1.5.0-alpha05 are released. Version 1.5.0-alpha05 contains these commits.

Bug Fixes

  • ComponentActivity's onPanelClosed() now calls the super onPanelClosed() as well, fixing an issue where the onContextMenuClosed method would not be called. (Ib6f77)

Version 1.5.0-alpha04

March 23, 2022

androidx.activity:activity:1.5.0-alpha04, androidx.activity:activity-compose:1.5.0-alpha04, and androidx.activity:activity-ktx:1.5.0-alpha04 are released. Version 1.5.0-alpha04 contains these commits.

Bug Fixes

  • SavedStateViewFactory now supports using CreationExtras even when it was initialized with a SavedStateRegistryOwner. If extras are provided, the initialized arguments are ignored. (I6c43b, b/224844583)

Version 1.5.0-alpha03

February 23, 2022

androidx.activity:activity:1.5.0-alpha03, androidx.activity:activity-compose:1.5.0-alpha03, and androidx.activity:activity-ktx:1.5.0-alpha03 are released. Version 1.5.0-alpha03 contains these commits.

API Changes

  • You can now pass CreationExtras to the activity by viewModels() function (I6a3e6, b/217600303)

Version 1.5.0-alpha02

February 9, 2022

androidx.activity:activity:1.5.0-alpha02, androidx.activity:activity-compose:1.5.0-alpha02, and androidx.activity:activity-ktx:1.5.0-alpha02 are released. Version 1.5.0-alpha02 contains these commits.

New Features

  • ComponentActivity now implements the OnPictureInPictureModeChangedProvider interface to allow any component to receive picture-in-picture mode change events. (I9f567)
  • ComponentActivity now implements the OnMultiWindowModeChangedProvider interface to allow any component to receive multi-window mode change events. (I62d91)

Version 1.5.0-alpha01

January 26, 2022

androidx.activity:activity:1.5.0-alpha01, androidx.activity:activity-compose:1.5.0-alpha01, and androidx.activity:activity-ktx:1.5.0-alpha01 are released. Version 1.5.0-alpha01 contains these commits.

New Features

  • ComponentActivity now integrates with ViewModel CreationExtras, introduced as part of Lifecycle 2.5.0-alpha01. (Ie7e00, b/207012584)
  • Added ComponentDialog, a subclass of Dialog that includes an OnBackPressedDispatcher that will be called when the system back button is pressed when the dialog is visible. Importantly, this subclass also sets the ViewTreeOnBackPressedDispatcherOwner, allowing views a generic way to retrieve the correct dispatcher whether it exists in a ComponentActivity or a ComponentDialog. (I8a1bc)
  • ComponentActivity now implements the new OnNewIntentProvider interface to allow any component to receive these events. (If1f8b)
  • ComponentActivity now implements the new OnConfigurationChangedProvider interface to allow any component to receive these events. (If623b)
  • ComponentActivity now implements the new OnTrimMemoryProvider interface to allow any component to receive these events. (Ia9295)

API Changes

  • The no parameter constructor for ActivityResultContracts.CreateDocument has been deprecated and replaced with a new constructor that takes a concrete mime type (e.g., "image/png") as is required by Intent.ACTION_CREATE_DOCUMENT. (I2bec6)
  • The OnBackPressedDispatcherOwner associated with a View can now be retrieved via the ViewTreeOnBackPressedDispatcherOwner, rather than relying on casting the Context. (I74685)

Bug Fixes

  • Fixed a crash when accessing a ViewModel for the very first time from a registerForActivityResult() callback or the callbacks to a LifecycleObserver added as part of init of a ComponentActivity. (Ife83f)

Version 1.4.0

Version 1.4.0

October 27, 2021

androidx.activity:activity:1.4.0, androidx.activity:activity-compose:1.4.0, and androidx.activity:activity-ktx:1.4.0 are released. Version 1.4.0 contains these commits.

Important changes since 1.3.0

  • AndroidX ComponentActivity now implements the MenuHost interface. This allows any component to add menu items to the ActionBar by adding a MenuProvider instance to the activity. Each MenuProvider can optionally be added with a Lifecycle that will automatically control the visibility of those menu items based on the Lifecycle state and handle the removal of the MenuProvider when the Lifecycle is destroyed.
  • The ActivityResultContract class has been rewritten in Kotlin to ensure that developers writing custom contracts in Kotlin can define the correct nullability for their input and output classes.
  • The ActivityResultContracts class and its contracts have been rewritten in Kotlin to ensure the proper nullability.

Version 1.4.0-rc01

October 13, 2021

androidx.activity:activity:1.4.0-rc01, androidx.activity:activity-compose:1.4.0-rc01, and androidx.activity:activity-ktx:1.4.0-rc01 are released. Version 1.4.0-rc01 contains these commits.

Bug Fixes

  • The ActivityResultRegistry will no longer return a result to the ActivityResultCallback when the launch call throws any Exception. (If4f91, b/200845664)

Version 1.4.0-beta01

September 29, 2021

androidx.activity:activity:1.4.0-beta01, androidx.activity:activity-compose:1.4.0-beta01, and androidx.activity:activity-ktx:1.4.0-beta01 are released. Version 1.4.0-beta01 contains these commits.

API Changes

  • Fixed the type for the ActivityResultContracts.OpenMultipleDocuments and ActivityResultContracts.GetMultipleContents that caused then to use an output type of List<? extends Uri> when using the code from the Java programming language. (If71de)
  • Public constants within the ActivityResultContracts.StartActivityForResult, ActivityResultContracts.StartIntentSenderForResult, and ActivityResultContracts.RequestMultiplePermissions classes are now accessible when using Kotlin via their now public Companion objects. (aosp/1832555)

Documentation Updates

  • The deprecation message for APIs now handled by the Activity Result APIs, namely startActivityForResult, startIntentSenderForResult, onActivityResult, requestPermissions, and onRequestPermissionsResult, have all been expanded with more details. (cce80f)

Version 1.4.0-alpha02

September 15, 2021

androidx.activity:activity:1.4.0-alpha02, androidx.activity:activity-compose:1.4.0-alpha02, and androidx.activity:activity-ktx:1.4.0-alpha02 are released. Version 1.4.0-alpha02 contains these commits.

New Features

  • The activity-compose artifact now contains a LaunchDuringComposition lint error that prevents you from calling the launch method of ActivityResultLauncher as part of composition as composition should be side-effect free. Use the APIs for handling side-effects. (7c2bbe, b/191347220)

API Changes

  • The ActivityResultContract class has been rewritten in Kotlin to ensure that developers writing custom contracts in Kotlin can define the correct nullability for their input and output classes. (I8a8f5)
  • The ActivityResultContracts class and its contracts have been rewritten in Kotlin to ensure the proper nullability. (I69802)

Version 1.4.0-alpha01

September 1, 2021

androidx.activity:activity:1.4.0-alpha01, androidx.activity:activity-compose:1.4.0-alpha01, and androidx.activity:activity-ktx:1.4.0-alpha01 are released. Version 1.4.0-alpha01 contains these commits.

New Features

  • AndroidX ComponentActivity now implements the MenuHost interface.. This allows any component to add menu items to the ActionBar by adding a MenuProvider instance to the activity. Each MenuProvider can optionally be added with a Lifecycle that will automatically control the visibility of those menu items based on the Lifecycle state and handle the removal of the MenuProvider when the Lifecycle is destroyed. (I3b608):
/**
  * Using the addMenuProvider() API directly in your Activity
  **/
class ExampleActivity : ComponentActivity(R.layout.activity_example) {

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    // Add menu items without overriding methods in the Activity
   addMenuProvider(object : MenuProvider {
      override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
        // Add menu items here
        menuInflater.inflate(R.menu.example_menu, menu)
      }

      override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
        // Handle the menu selection
        return true
      }
    })
  }
}

/**
  * Using the addMenuProvider() API in a Fragment
  **/
class ExampleFragment : Fragment(R.layout.fragment_example) {

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    // The usage of an interface lets you inject your own implementation
    val menuHost: MenuHost = requireActivity()
  
    // Add menu items without using the Fragment Menu APIs
    // Note how we can tie the MenuProvider to the viewLifecycleOwner
    // and an optional Lifecycle.State (here, RESUMED) to indicate when
    // the menu should be visible
    menuHost.addMenuProvider(object : MenuProvider {
      override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
        // Add menu items here
        menuInflater.inflate(R.menu.example_menu, menu)
      }

      override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
        // Handle the menu selection
        return true
      }
    }, viewLifecycleOwner, Lifecycle.State.RESUMED)
  }

Behavior Changes

  • The ActivityResultRegistry will now throw an IllegalStateException when attempting to call launch() on an ActivityResultLauncher that has not be registered or that has been unregistered. (Ida75d, b/192567522)

External Contribution

  • Thanks dmitrilc for fixing a typo in the ActivityResult documentation. (#221)

Version 1.3.1

Version 1.3.1

August 4, 2021

androidx.activity:activity:1.3.1, androidx.activity:activity-compose:1.3.1, and androidx.activity:activity-ktx:1.3.1 are released. Version 1.3.1 contains these commits.

Dependency updates

  • Activity now depends on Kotlin 1.5.21.
  • Activity Compose now depends on Compose 1.0.1.

Version 1.3.0

Version 1.3.0

July 28, 2021

androidx.activity:activity:1.3.0, androidx.activity:activity-compose:1.3.0, and androidx.activity:activity-ktx:1.3.0 are released. Version 1.3.0 contains these commits.

Important changes since 1.2.0

  • Activity Compose artifact - The activity-compose artifact provides the setContent extension method for hosting your Jetpack Compose UI in an activity and Compose specific wrappers for interacting with the ComponentActivity APIs for handling the system back button and the Activity Result APIs. See the documentation for more details.
  • CaptureVideo contract - The CaptureVideo ActivityResultContract replaces the now deprecated TakeVideo contract and returns a boolean denoting success that works across many camera apps.
  • Picture-In-Picture Hint View Tracking - Users of activity-ktx can now use the trackPipAnimationHintView extension method on Activity to automatically rebuild the PictureInPictureParams with the new position of the view as it changes position relative to the window.

Version 1.3.0-rc02

July 14, 2021

androidx.activity:activity:1.3.0-rc02, androidx.activity:activity-compose:1.3.0-rc02, and androidx.activity:activity-ktx:1.3.0-rc02 are released. Version 1.3.0-rc02 contains these commits.

Bug Fixes

  • The ActivityResultRegistry callbacks are now properly saved and restored so callbacks are not duplicated in the savedState. (I97816, b/191893160)

Version 1.3.0-rc01

July 1, 2021

androidx.activity:activity:1.3.0-rc01, androidx.activity:activity-compose:1.3.0-rc01, and androidx.activity:activity-ktx:1.3.0-rc01 are released with no changes from 1.3.0-beta02. Version 1.3.0-rc01 contains these commits.

Version 1.3.0-beta02

June 16, 2021

androidx.activity:activity:1.3.0-beta02, androidx.activity:activity-compose:1.3.0-beta02, and androidx.activity:activity-ktx:1.3.0-beta02 are released. Version 1.3.0-beta02 contains these commits.

Updated activity-compose to depend on Compose 1.0.0-beta09. androidx.compose.ui:ui-test-junit4 now has a compile time dependency on activity-compose.

Version 1.3.0-beta01

June 2, 2021

androidx.activity:activity:1.3.0-beta01, androidx.activity:activity-compose:1.3.0-beta01, and androidx.activity:activity-ktx:1.3.0-beta01 are released. Version 1.3.0-beta01 contains these commits.

API Changes

  • The previously deprecated @Composable registerForActivityResult() method has been removed. Please use rememberLauncherForActivityResult(). (Ic39d3)

Version 1.3.0-alpha08

May 18, 2021

androidx.activity:activity:1.3.0-alpha08, androidx.activity:activity-compose:1.3.0-alpha08, and androidx.activity:activity-ktx:1.3.0-alpha08 are released. Version 1.3.0-alpha08 contains these commits.

New Features

  • The new CaptureVideo ActivityResultContract returns a boolean to your ActivityResultCallback indicating if your video was successfully saved to the given URI. This replaces the now deprecated TakeVideo contract as camera apps very rarely supported returning a thumbnail bitmap, making the result unhelpful. (Ie21f2, b/185938070)
  • Added new API Activity#setPipAnimationHintView to update the PipParams' source rect hint whenever the view moves. (I9063d)

API Changes

  • The rememberLauncherForActivityResult function now returns a launcher that deprecates the unregister() function - registration and unregistering the launcher is handled automatically by rememberLauncherForActivityResult. (I2443e)

Compose Compatibility

  • androidx.activity:activity-compose:1.3.0-alpha08 is only compatible with Compose version 1.0.0-beta07 and above.

Version 1.3.0-alpha07

April 21, 2021

androidx.activity:activity:1.3.0-alpha07, androidx.activity:activity-compose:1.3.0-alpha07, and androidx.activity:activity-ktx:1.3.0-alpha07 are released. Version 1.3.0-alpha07 contains these commits.

Bug Fixes

  • rememberLauncherForActivityResult now returns a stable reference to the same ActivityResultLauncher instance even if the contract changes due to recompositions. (Id2d6d)
  • Using unstable versions of Fragments above 1.3.0 will no longer throw a false positive lint error telling you to use 1.3.0. (aosp/1670206, b/184847092)

Version 1.3.0-alpha06

April 7, 2021

androidx.activity:activity:1.3.0-alpha06, androidx.activity:activity-compose:1.3.0-alpha06, and androidx.activity:activity-ktx:1.3.0-alpha06 are released. Version 1.3.0-alpha06 contains these commits.

API Changes

  • The registerForActivityResult() API has been renamed to rememberLauncherForActivityResult() to better indicate that the returned ActivityResultLauncher is a managed object that is remembered on your behalf. Attempting to call unregister the returned ActivityResultLauncher will now throw an error. (I2bb6d)
  • LocalOnBackPressedDispatcherOwner.current and LocalActivityResultRegistryOwner.current now return a nullable value to better determine whether it is available in the current composition. APIs that requires those APIs, such as BackHandler and rememberLauncherForActivityResult(), respectively, will now throw a more descriptive error if the underlying owner is not found. NavHost now works even when an OnBackPressedDispatcherOwner is not found, such is the case when previewing the NavHost. (I7d8b4)

Bug Fixes

  • The BackHandler will now properly intercept back presses in the event that the Activity is STOPPED, then STARTED again, and other callbacks were added with a LifecycleOwner. (I71de6, b/182284739)
  • Using the launch() method extension with a custom ActivityResultContract that has a Unit input will no longer cause a NullPointerException (I76282, b/183837954)

Version 1.3.0-alpha05

March 24, 2021

androidx.activity:activity:1.3.0-alpha05, androidx.activity:activity-compose:1.3.0-alpha05, and androidx.activity:activity-ktx:1.3.0-alpha05 are released. Version 1.3.0-alpha05 contains these commits.

Bug Fixes

  • From Activity 1.2.2: Fixed an issue in the InvalidFragmentVersionForActivityResult lint check that led to a false positive when using Fragment 1.3.1 or higher. (I54da1, b/182388985)
  • From Activity 1.2.2: ComponentActivity now avoids a ClassNotFoundException when launching an Intent from an ActivityResultContract that was previously held as an extra in another Intent. (Ieff05, b/182906230)

Dependency Updates

Version 1.3.0-alpha04

March 10, 2021

androidx.activity:activity:1.3.0-alpha04, androidx.activity:activity-compose:1.3.0-alpha04, and androidx.activity:activity-ktx:1.3.0-alpha04 are released. Version 1.3.0-alpha04 contains these commits.

Bug Fixes

  • From Activity 1.2.1: RequestMultiplePermissions now always returns results for all requested permissions instead of only permissions that weren’t previously granted. (I50bc3, b/180884668)
  • From Activity 1.2.1: ActivityResultRegistry now ensures that in progress launch() requests will return their results even if you unregister(), then register() again with the same key. (I9ef34, b/181267562)
  • Activity Compose no longer adds test dependencies to the runtime classpath. (Ifd8b3)
  • Fixed an issue with BackHandler where the previously set onBack lambda was still being used after recomposition. (8eb5eb)

Version 1.3.0-alpha03

February 24, 2021

androidx.activity:activity:1.3.0-alpha03, androidx.activity:activity-compose:1.3.0-alpha03, and androidx.activity:activity-ktx:1.3.0-alpha03 are released. Version 1.3.0-alpha03 contains these commits.

New Features

  • There is a now a Composable registerForActivityResult function for getting results from activities within composables. (Ia7851, b/172690553)

API Changes

  • LocalOnBackPressedDispatcherOwner now has a provides functions that can be used with CompositionLocalProvider, replacing the asProvidableCompositionLocal() API. (I45d24)

Version 1.3.0-alpha02

February 10, 2021

androidx.activity:activity:1.3.0-alpha02, androidx.activity:activity-compose:1.3.0-alpha02, and androidx.activity:activity-ktx:1.3.0-alpha02 are released. Version 1.3.0-alpha02 contains these commits.

Bug Fixes

  • Fixed an issue in Activity Compose 1.3.0-alpha01 that causes a NoSuchMethodError: No static method setContent exception when using Compose 1.0.0-alpha12. All Compose users should depend on 1.3.0-alpha02 and above. (b/179911234)

API Changes

  • The BackHandler API can be used to allow a Composable to intercept the system back button. (I58ed5, b/172154006)

Version 1.3.0-alpha01

February 10, 2021

androidx.activity:activity:1.3.0-alpha01, androidx.activity:activity-compose:1.3.0-alpha01, and androidx.activity:activity-ktx:1.3.0-alpha01 are released. Version 1.3.0-alpha01 contains these commits.

New Features

  • The new activity-compose artifact provides Jetpack Compose specific helpers for androidx.activity specific APIs.
    • ComponentActivity.setContent has moved from androidx.compose.ui.platform.setContent to androidx.activity.compose.setContent. (Icf416)

Known Issues

  • Using Activity Compose 1.3.0-alpha01 and libraries that depend on it, such as androidx.compose.ui:ui-test-junit4:1.0.0-alpha12, will result in a NoSuchMethodError: No static method setContent exception. (b/179911234)

Version 1.2.4

Version 1.2.4

July 21, 2021

androidx.activity:activity:1.2.4 and androidx.activity:activity-ktx:1.2.4 are released. Version 1.2.4 contains these commits.

Bug Fixes

Version 1.2.3

Version 1.2.3

May 5, 2021

androidx.activity:activity:1.2.3 and androidx.activity:activity-ktx:1.2.3 are released. Version 1.2.3 contains these commits.

Bug Fixes

  • Using the launch() method extension with a custom ActivityResultContract that has a Unit input will no longer cause a NullPointerException (I76282, b/183837954)
  • Fixed a false positive lint error telling you to use Fragment 1.3.0 when using an snapshot, alpha, beta, or RC build of a newer version of Fragments. (f4a57e, b/184847092)

Version 1.2.2

Version 1.2.2

March 24, 2021

androidx.activity:activity:1.2.2 and androidx.activity:activity-ktx:1.2.2 are released. Version 1.2.2 contains these commits.

Bug Fixes

  • Fixed an issue in the InvalidFragmentVersionForActivityResult lint check that led to a false positive when using Fragment 1.3.1 or higher. (I54da1, b/182388985)
  • ComponentActivity now avoids a ClassNotFoundException when launching an Intent from an ActivityResultContract that was previously held as an extra in another Intent. (Ieff05, b/182906230)

Dependency Updates

Version 1.2.1

Version 1.2.1

March 10, 2021

androidx.activity:activity:1.2.1 and androidx.activity:activity-ktx:1.2.1 are released. Version 1.2.1 contains these commits.

Bug Fixes

  • RequestMultiplePermissions now always returns results for all requested permissions instead of only permissions that weren’t previously granted. (I50bc3, b/180884668)
  • ActivityResultRegistry now ensures that in progress launch() requests will return their results even if you unregister(), then register() again with the same key. (I9ef34, b/181267562)

Version 1.2.0

Version 1.2.0

February 10, 2021

androidx.activity:activity:1.2.0 and androidx.activity:activity-ktx:1.2.0 are released. Version 1.2.0 contains these commits.

Major changes since 1.1.0

  • Activity Result APIs: ComponentActivity now provides an ActivityResultRegistry that lets you handle startActivityForResult()+onActivityResult() as well as requestPermissions()+onRequestPermissionsResult() flows without overriding methods in your Activity or Fragment, brings increased type safety via ActivityResultContract, and provides hooks for testing these flows. See the updated Getting a Result from an Activity.
  • ContextAware: ComponentActivity now implements ContextAware, allowing you to add one or more OnContextAvailableListener instances which will receive a callback before the base Activity.onCreate().

    • A suspending Kotlin extension withContextAvailable() allows you to run a non-suspending block when the Context becomes available and return a result.
    • This API is used by FragmentActivity in Fragment 1.3.0 to restore the state of the FragmentManager. Any listeners added to subclasses of FragmentActivity will run after that listener.
    • This API is used by AppCompatActivity in AppCompat 1.3.0-alpha02 or higher. Any listeners added to subclasses of AppCompatActivity will run after that listener.
  • ViewTree Support: ComponentActivity now supports the ViewTreeLifecycleOwner.get(View), ViewTreeViewModelStoreOwner.get(View), and ViewTreeSavedStateRegistryOwner APIs added in Lifecycle 2.3.0 and SavedState 1.1.0 such that it will return the Activity as the LifecycleOwner, ViewModelStoreOwner, and SavedStateRegistryOwner for any Views directly added to the ComponentActivity.

  • reportFullyDrawn() backport - The Activity method of reportFullyDrawn() has been backported in ComponentActivity to work on all API levels, fixing a crash on API 19 and adding tracing for this method for all API levels.

Version 1.2.0-rc01

December 16, 2020

androidx.activity:activity:1.2.0-rc01 and androidx.activity:activity-ktx:1.2.0-rc01 are released. Version 1.2.0-rc01 contains these commits.

Bug Fixes

  • The ActivityResultRegistry now always restores the exact state that was saved. (Idd56b)
  • Add tracing to ComponentActivity.reportFullyDrawn (Ic7632)

External Contribution

  • ComponentActivity now overrides reportFullyDrawn(), allowing it to be called on all API levels and fixing a crash when calling this method without the appropriate system permission on API 19 devices. Thanks Simon Schiller! (b/163239764, #103)

Version 1.2.0-beta02

December 2, 2020

androidx.activity:activity:1.2.0-beta02 and androidx.activity:activity-ktx:1.2.0-beta02 are released. Version 1.2.0-beta02 contains these commits.

Bug Fixes

  • Fixed an issue where the Activity Result API would not wait for the Lifecycle to be STARTED before delivering results when registered with a Lifecycle. (I109ea)

External Contribution

  • Updated the documentation for launch() to explicitly call out that it can throw an ActivityNotFoundException. Thanks Michał Zieliński! (aosp/1493580)

Version 1.2.0-beta01

October 1, 2020

androidx.activity:activity:1.2.0-beta01 and androidx.activity:activity-ktx:1.2.0-beta01 are released. Version 1.2.0-beta01 contains these commits.

Bug Fixes

  • The ActivityResultRegistry now randomly generates integers until it finds one that is unallocated to use as a request code register(), thus preventing the possible integer overflow caused by incrementing request codes. (b/168779518)

  • Lifecycle observers are properly removed when calling unregister() on an ActivityResultLauncher. (b/165608393)

Behavior Changes

  • The ActivityResultRegistry now throws an IllegalStateException when attempting to call register() with a LifecycleOwner whose Lifecycle has already reached STARTED. (b/165435866)

Documentation Updated

  • ContextAware documentation links to LifecycleOwner to highlight Lifecycle callbacks as the appropriate place for creation and destruction events. (aosp/1414152)

Version 1.2.0-alpha08

August 19, 2020

androidx.activity:activity:1.2.0-alpha08 and androidx.activity:activity-ktx:1.2.0-alpha08 are released. Version 1.2.0-alpha08 contains these commits.

New Features

  • ComponentActivity now implements ContextAware, allowing you to add one or more OnContextAvailableListener instances which will receive a callback before the base Activity.onCreate(). (b/161390636)
    • A suspending Kotlin extension withContextAvailable() allows you to run a non-suspending block when the Context becomes available and return a result. (I8290c)
    • This API is used by FragmentActivity in Fragment 1.3.0-alpha08 to restore the state of the FragmentManager. Any listeners added to subclasses of FragmentActivity will run after that listener. (I513da)
    • This API is used by AppCompatActivity in AppCompat 1.3.0-alpha02. Any listeners added to subclasses of AppCompatActivity will run after that listener. (I513da)

Bug Fixes

  • Fixed an issue with the ActivityResultFragmentVersionDetector Lint check that caused it to break when using Lint 27.1.0 or higher. (b/162155191)

Version 1.2.0-alpha07

July 22, 2020

androidx.activity:activity:1.2.0-alpha07 and androidx.activity:activity-ktx:1.2.0-alpha07 are released. Version 1.2.0-alpha07 contains these commits.

New Features

  • Added a new InvalidFragmentVersionForActivityResult lint check that verifies that you are using Fragment 1.3.0-alpha07 when using the Activity Result API, avoiding runtime crashes due to “invalid request code” issues and non-functioning permission requests caused by using older versions of Fragments. (b/152554847)

External Contribution

  • Fixed an ArrayIndexOutOfBoundsException when parsing the results for the RequestPermission Activity Result contract. (I8f9e3, b/161057605)

Version 1.2.0-alpha06

June 10, 2020

androidx.activity:activity:1.2.0-alpha06 and androidx.activity:activity-ktx:1.2.0-alpha06 are released. Version 1.2.0-alpha06 contains these commits.

New Features

  • You can now destructure the ActivityResult class in kotlin to directly access the requestCode and intent. (b/157212935)
  • ActivityResultLauncher now allows you to get the ActivityResultContract that was used to register the launcher. (b/156875743)

API Changes

  • Breaking change: The invoke() method on ActivityResultRegistry has been renamed to onLaunch(). (b/157496491)
  • The OpenMultipleDocuments contract now returns an empty list instead of null to the registered callback if no result is returned. (b/157348014)

Version 1.2.0-alpha05

May 20, 2020

androidx.activity:activity:1.2.0-alpha05 and androidx.activity:activity-ktx:1.2.0-alpha05 are released. Version 1.2.0-alpha05 contains these commits.

New Features

API Changes

  • The TakePicture contract now returns a boolean indicating success rather than a thumbnail Bitmap as this was very rarely supported by camera apps when writing the image to the provided Uri. (b/154302879)
  • The invoke() extensions on ActivityResultLauncher have been removed in favor of explicitly using launch() to better indicate that these are asynchronous operations. Kotlin extensions for launch have been added to the androidx.activity.result package for ActivityResultLauncher<Void> and ActivityResultLauncher<Unit> that remove the need to pass in null or Unit, respectively, mirroring that behavior from the previously invoke() extensions. (aosp/1304674, aosp/1304675)
  • The IntentSenderRequest.Builder methods for setFlagsMask() and setFlagsValues() has been combined into a single setFlags() method. (aosp/1302111)

Bug Fixes

  • When registering an ActivityResultCallback with a LifecycleOwner, fixed an issue where the callback would be triggered before the state reaches STARTED. (aosp/1309744)

Behavior Changes

  • The ActivityResultRegistry now generates request codes starting at 0xFFFF rather than at 0, preventing overlap when using startActivityForResult() or requestPermissions() in an activity. (aosp/1302324)

Version 1.2.0-alpha04

April 29, 2020

androidx.activity:activity:1.2.0-alpha04 and androidx.activity:activity-ktx:1.2.0-alpha04 are released. Version 1.2.0-alpha04 contains these commits.

New Features

  • Added a contract that can call startIntentSenderForResult to the ActivityResult APIs. (b/153007517)

API Changes

  • The prepareCall() method has been renamed to registerForActivityResult(), both on ComponentActivity here and in Fragment 1.3.0-alpha04. (aosp/1278717)
  • The GetContents, OpenDocuments, and RequestPermissions contracts have been renamed to GetMultipleContents, OpenMultipleDocuments, and RequestMultiplePermissions, respectively. (aosp/1280161)
  • ComponentActivity now implements the ActivityResultRegisteryOwner interface. (aosp/1290888)
  • - The startActivityForResult()/onActivityResult() and onRequestPermissionsResult() APIs on ComponentActivity have been deprecated. Please use the Activity Result APIs. (b/154751887)

Bug Fixes

  • When using the GetMultipleContents and OpenMultipleDocuments contracts and selecting a single item, it is now correctly returned to your callback. (b/152941153)

Version 1.2.0-alpha03

April 1, 2020

androidx.activity:activity:1.2.0-alpha03 and androidx.activity:activity-ktx:1.2.0-alpha03 are released. Version 1.2.0-alpha03 contains these commits.

New Features

  • Added the TakeVideo, PickContact, GetContent, GetContents, OpenDocument, OpenDocuments, OpenDocumentTree, and CreateDocument contracts to the set of pre-built contracts provided by ActivityResultContracts. (aosp/1262482, aosp/1266916, aosp/1268960)
  • The Activity Result APIs now support launching an activity for result with an optional ActivityOptionsCompat. (b/151860054)

API Changes

  • The TakePicture contract now takes a Uri input for where the image should be stored. The previous contract that does not take any input has been renamed to TakePicturePreview. (aosp/1262482)
  • The registerActivityResultCallback() method on ActivityResultRegistry has been renamed to register(). (aosp/1267621)
  • The dispose() method on ActivityResultLauncher has been renamed to unregister() and the unregisterResultCallback() on ActivityResultRegistry has been removed. (aosp/1267621)
  • The createIntent() method of ActivityResultContact now takes a Context in addition to the input to make it possible to create explicit Intents. (aosp/1238800)
  • An ActivityResultContract can now override getSynchronousResult() to deliver a result without calling startActivityForResult. This is used by the RequestPermission and RequestPermissions contracts to correctly deliver a ‘granted’ status if the requested permissions are already granted. (b/151110799)
  • The previously available Dial contract has been removed as that Intent is not meant to be used with startActivityForResult(). (aosp/1266916)
  • Many of the Activity Result APIs not meant to be extended are now final. This includes getActivityResultRegistry(), the prepareCall() methods, all methods of ActivityResultRegistry except invoke(), and a number of the default contracts that do not support optional extras. (b/152439361)

Bug Fixes

  • Fixed a NullPointerException in ActivityResultRegistry when attempting to deliver results to a callback that has not yet been re-registered after a configuration change; ActivityResultRegistry now holds onto these pending results and delivers them when the callback is re-registered. (b/152137004)

Version 1.2.0-alpha02

March 18, 2020

androidx.activity:activity:1.2.0-alpha02 and androidx.activity:activity-ktx:1.2.0-alpha02 are released. Version 1.2.0-alpha02 contains these commits.

New Features

  • ActivityResultRegistry: ComponentActivity now provides an ActivityResultRegistry that lets you handle the startActivityForResult()+onActivityResult() as well as requestPermissions()+onRequestPermissionsResult() flows without overriding methods in your Activity or Fragment, brings increased type safety via ActivityResultContract, and provides hooks for testing these flows. See the updated Getting a Result from an Activity. (b/125158199)

Version 1.2.0-alpha01

March 4, 2020

androidx.activity:activity:1.2.0-alpha01 and androidx.activity:activity-ktx:1.2.0-alpha01 are released. Version 1.2.0-alpha01 contains these commits.

New Features

  • Added support for the ViewTreeLifecycleOwner.get(View) API added in Lifecycle 2.3.0-alpha01 such that it will return the Activity as the LifecycleOwner for any Views directly added to the Activity. (aosp/1182955)

Bug Fixes

  • Fixed a regression introduced in Activity 1.1.0 when running on older versions of the platform where onBackPressed() would cause an IllegalStateException due to a bug in the android.app.FragmentManager. (b/146290338)

Version 1.1.0

Version 1.1.0

January 22, 2020

androidx.activity:activity:1.1.0 is released. Version 1.1.0 contains these commits.

Important changes since 1.0.0

  • Lifecycle ViewModel SavedState Integration: SavedStateViewModelFactory is now the default factory used when using by viewModels(), the ViewModelProvider constructor, or ViewModelProviders.of() with a ComponentActivity or its subclasses.

Version 1.1.0-rc03

December 4, 2019

androidx.activity:activity:1.1.0-rc03 and androidx.activity:activity-ktx:1.1.0-rc03 are released. Version 1.1.0-rc03 contains these commits.

Dependency changes

  • Activity now depends on Lifecycle 2.2.0-rc03 and Lifecycle ViewModel SavedState 1.0.0-rc03.

Version 1.1.0-rc02

November 7, 2019

androidx.activity:activity:1.1.0-rc02 and androidx.activity:activity-ktx:1.1.0-rc02 are released. Version 1.1.0-rc02 contains these commits.

Dependency changes

  • Activity now depends on lifecycle 2.2.0-rc02.

Version 1.1.0-rc01

October 23, 2019

androidx.activity:activity:1.1.0-rc01 and androidx.activity:activity-ktx:1.1.0-rc01 are released with no changes from 1.1.0-beta01. Version 1.1.0-rc01 contains these commits.

Version 1.1.0-beta01

October 9, 2019

androidx.activity:activity:1.1.0-beta01 and androidx.activity:activity-ktx:1.1.0-beta01 are released. Version 1.1.0-beta01 contains these commits.

Dependency changes

  • Activity now depends on SavedState 1.0.0 stable.

Version 1.1.0-alpha03

September 5, 2019

androidx.activity:activity:1.1.0-alpha03 and androidx.activity:activity-ktx:1.1.0-alpha03 are released. The commits included in this version can be found here.

New features

  • Activity now depends on Core 1.1.0 stable.

Bug fixes

Version 1.1.0-alpha02

August 7, 2019

androidx.activity:activity:1.1.0-alpha02 and androidx.activity:activity-ktx:1.1.0-alpha02 are released. The commits included in this version can be found here.

New features

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

Version 1.1.0-alpha01

July 2, 2019

androidx.activity:activity:1.1.0-alpha01 and androidx.activity:activity-ktx:1.1.0-alpha01 are released. The commits included in this version can be found here.

New features

  • activity now depends on Lifecycle 2.2.0-alpha02. (aosp/1007817)
  • activity-ktx added a dependency on lifecycle-runtime-ktx; you no longer need to explicitly add it to your dependencies when using activity-ktx or libraries that depend on activity-ktx (such as fragment-ktx). (aosp/987162)

Version 1.0.0

Version 1.0.0

September 5, 2019

androidx.activity:activity:1.0.0 and androidx.activity:activity-ktx:1.0.0 are released. The commits included in this version can be found here.

Major Features of 1.0.0

  • ComponentActivity: ComponentActivity serves as the new base class for FragmentActivity in Fragment 1.1.0 and, by extension, AppCompatActivity in AppCompat 1.1.0.
  • activity-ktx: The activity-ktx module includes a by viewModels Kotlin property extension for accessing ViewModels. This module is automatically included when you include fragment-ktx from Fragment 1.1.0.
  • OnBackPressedDispatcher: As a composable alternative to overriding onBackPressed(), you can now register a OnBackPressedCallback from any LifecycleOwner (such as a fragment) to intercept system back button events. A lambda with receiver version addCallback has been added to activity-ktx. See Provide custom back navigation documentation for more details.
  • onRetainCustomNonConfigurationInstance deprecation: the onRetainCustomNonConfigurationInstance() and the related getLastCustomNonConfigurationInstance() APIs have been deprecated. It is strongly recommended to use ViewModels to store non-configuration state as they offer a composable solution suitable for any ViewModelStoreOwner that makes the ownership of the retained objects clear and provides an onCleared() callback for cleaning up resources when the activity is finally destroyed.

Version 1.0.0-rc01

July 2, 2019

androidx.activity:activity:1.0.0-rc01 and androidx.activity:activity-ktx:1.0.0-rc01 are released with no changes from 1.0.0-beta01. The commits included in this version can be found here.

Version 1.0.0-beta01

June 5, 2019

androidx.activity::activity:1.0.0-beta01 and androidx.activity:activity-ktx:1.0.0-beta01 are released with no changes from 1.0.0-alpha08. The commits included in this version can be found here.

Version 1.0.0-alpha08

May 7, 2019

androidx.activity:activity:1.0.0-alpha08 and androidx.activity:activity-ktx:1.0.0-alpha08 are released. The commits included in this version can be found here.

API changes

  • Breaking change: The previously deprecated addOnBackPressedCallback and removeOnBackPressedCallback methods on ComponentActivity have been removed. aosp/953857
  • The setEnabled() and isEnabled() methods of OnBackPressedCallback are now final. b/131416833
  • The remove() method of OnBackPressedCallback is now final. aosp/952720
  • OnBackPressedDispatcher now has public constructors, allowing you to construct your own instances for testing, etc. aosp/953431
  • onBackPressed() for ComponentActivity is now explicitly marked as @MainThread aosp/952721

Bug fixes

  • Fixed a ConcurrentModificationException when calling remove() from within the handleOnBackPressed() method of a OnBackPressedCalback that was added with a LifecycleOwner. b/131765095

Version 1.0.0-alpha07

April 25th, 2019

androidx.activity:activity:1.0.0-alpha07 and androidx.activity:activity-ktx:1.0.0-alpha07 are released. The commits included in this version can be found here.

API changes

This release makes significant changes to the handling of the onBackPressed(). See the updated custom back documentation for more details.

  • The methods for OnBackPressedCallback and OnBackPressedDispatcher have been marked as @MainThread. (aosp/943813)
  • The handleOnBackPressed() method no longer returns a boolean. Instead, OnBackPressedCallback is now an abstract class that can be enabled or disabled - only when the new isEnabled() method returns true will handleOnBackPressed() be called, in which you must handle the back button. (aosp/944518)
  • The addCallback methods of OnBackPressedDispatcher no longer return a Cancellable instance. OnBackPressedCallback now contain a remove() method that fulfill this functionality, allowing you to call remove() during handleOnBackPressed(). (aosp/944519) (aosp/946316)
  • activity-ktx now contains a receiver scoped callback for addCallback that accepts a lamdba that implements handleOnBackPressed() and has access to isEnabled and remove() (aosp/944520)

Version 1.0.0-alpha06

April 3rd, 2019

androidx.activity:activity:1.0.0-alpha06 and androidx.activity:activity-ktx:1.0.0-alpha06 are released. The commits included in this version can be found here.

API changes

  • ComponentActivity now contain a second constructor that takes a @LayoutRes int, which replaces the previous behavior of annotating your AppCompatActivity class with @ContentView. This approach works in both app and library modules. (b/128352521)
  • The OnBackPressedCallback related APIs on ComponentActivity have been deprecated in favor of the new OnBackPressedDispatcher, retrievable via getOnBackPressedDispatcher(). (aosp/922523)
  • Methods to add a new OnBackPressedCallback to the OnBackPressedDispatcher now return a Cancellable object, allowing removal of the callback without requiring an explicit reference to the OnBackPressedDispatcher. (aosp/922523)
  • Adding a OnBackPressedCallback with an associated LifecycleOwner now results in adding and removing the OnBackPressedCallback as the Lifecycle is started and stopped, respectively. (aosp/922523)

Version 1.0.0-alpha05

March 13th, 2019

androidx.activity:activity:1.0.0-alpha05 and androidx.activity:activity-ktx:1.0.0-alpha05 are released. The full list of commits included in this release can be found here.

New features

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

Version 1.0.0-alpha04

January 30, 2019

androidx.activity:activity 1.0.0-alpha04and androidx.activity:activity-ktx 1.0.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 using setContentView(). (aosp/837619)

API changes

  • 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/837619)

Bug fixes

  • The activity module now depends on version 2.1.0-alpha02 of ViewModel to match the activity-ktx module’s dependency.

Version 1.0.0-alpha03

December 17, 2018

androidx.activity 1.0.0-alpha03 is released.

New features

  • ComponentActivity now implements BundleSavedStateRegistryOwner and depends on the newly released SavedState library [aosp/815133]
  • ComponentActivity now works around an Android framework bug that would cause InputMethodManager to leak the last focused view [b/37122102]

Version 1.0.0-alpha02

December 3, 2018

API changes

  • Added a note that getLifecycle() 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/815834)

Version 1.0.0-alpha01

November 5, 2018

androidx.activity 1.0.0-alpha01 introduces ComponentActivity, a new base class of the existing FragmentActivity and AppCompatActivity.

New features

  • You can now register an OnBackPressedCallback via addOnBackPressedCallback to receive onBackPressed() callbacks without needing to override the method in your activity.
  • Added a new by viewModels() Kotlin property delegate for retrieving ViewModels from a ComponentActivity.
  • Pending input events (such as clicks) are now canceled in onStop().

API changes

  • The implementation of LifecycleOwner and ViewModelStoreOwner have been moved from FragmentActivity to ComponentActivity.
  • onRetainCustomNonConfigurationInstance has been deprecated. Use a ViewModel for storing objects that need to survive configuration changes.