Activity
Latest Update | Current Stable Release | Next Release Candidate | Beta Release | Alpha Release |
---|---|---|---|---|
April 21, 2021 | 1.2.2 | - | - | 1.3.0-alpha07 |
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:
dependencies { def activity_version = "1.2.2" // 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.
See the Issue Tracker documentation for more information.
Version 1.3.0
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 sameActivityResultLauncher
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 use1.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 torememberLauncherForActivityResult()
to better indicate that the returnedActivityResultLauncher
is a managed object that is remembered on your behalf. Attempting to callunregister
the returnedActivityResultLauncher
will now throw an error. (I2bb6d) LocalOnBackPressedDispatcherOwner.current
andLocalActivityResultRegistryOwner.current
now return a nullable value to better determine whether it is available in the current composition. APIs that requires those APIs, such asBackHandler
andrememberLauncherForActivityResult()
, respectively, will now throw a more descriptive error if the underlying owner is not found.NavHost
now works even when anOnBackPressedDispatcherOwner
is not found, such is the case when previewing theNavHost
. (I7d8b4)
Bug Fixes
- The
BackHandler
will now properly intercept back presses in the event that the Activity isSTOPPED
, thenSTARTED
again, and other callbacks were added with a LifecycleOwner. (I71de6, b/182284739) - Using the
launch()
method extension with a customActivityResultContract
that has aUnit
input will no longer cause aNullPointerException
(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 aClassNotFoundException
when launching anIntent
from anActivityResultContract
that was previously held as an extra in anotherIntent
. (Ieff05, b/182906230)
Dependency Updates
- From Activity 1.2.2: Activity now depends on Lifecycle
2.3.1
.
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 progresslaunch()
requests will return their results even if youunregister()
, thenregister()
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 setonBack
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 aprovides
functions that can be used withCompositionLocalProvider
, replacing theasProvidableCompositionLocal()
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 aNoSuchMethodError: No static method setContent
exception when using Compose1.0.0-alpha12
. All Compose users should depend on1.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 forandroidx.activity
specific APIs.ComponentActivity.setContent
has moved fromandroidx.compose.ui.platform.setContent
toandroidx.activity.compose.setContent
. (Icf416)
Known Issues
- Using Activity Compose
1.3.0-alpha01
and libraries that depend on it, such asandroidx.compose.ui:ui-test-junit4:1.0.0-alpha12
, will result in aNoSuchMethodError: No static method setContent
exception. (b/179911234)
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 aClassNotFoundException
when launching anIntent
from anActivityResultContract
that was previously held as an extra in anotherIntent
. (Ieff05, b/182906230)
Dependency Updates
- Activity now depends on Lifecycle
2.3.1
.
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 progresslaunch()
requests will return their results even if youunregister()
, thenregister()
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 anActivityResultRegistry
that lets you handlestartActivityForResult()
+onActivityResult()
as well asrequestPermissions()
+onRequestPermissionsResult()
flows without overriding methods in your Activity or Fragment, brings increased type safety viaActivityResultContract
, and provides hooks for testing these flows. See the updated Getting a Result from an Activity.
ContextAware
:ComponentActivity
now implementsContextAware
, allowing you to add one or moreOnContextAvailableListener
instances which will receive a callback before the baseActivity.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 theFragmentManager
. Any listeners added to subclasses ofFragmentActivity
will run after that listener. - This API is used by
AppCompatActivity
in AppCompat 1.3.0-alpha02 or higher. Any listeners added to subclasses ofAppCompatActivity
will run after that listener.
- A suspending Kotlin extension
ViewTree
Support:ComponentActivity
now supports theViewTreeLifecycleOwner.get(View)
,ViewTreeViewModelStoreOwner.get(View)
, andViewTreeSavedStateRegistryOwner
APIs added in Lifecycle2.3.0
and SavedState1.1.0
such that it will return the Activity as theLifecycleOwner
,ViewModelStoreOwner
, andSavedStateRegistryOwner
for any Views directly added to theComponentActivity
.
- reportFullyDrawn() backport - The
Activity
method ofreportFullyDrawn()
has been backported inComponentActivity
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 overridesreportFullyDrawn()
, 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 aLifecycle
. (I109ea)
External Contribution
- Updated the documentation for
launch()
to explicitly call out that it can throw anActivityNotFoundException
. 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 coderegister()
, thus preventing the possible integer overflow caused by incrementing request codes. (b/168779518)Lifecycle
observers are properly removed when callingunregister()
on anActivityResultLauncher
. (b/165608393)
Behavior Changes
- The
ActivityResultRegistry
now throws anIllegalStateException
when attempting to callregister()
with aLifecycleOwner
whoseLifecycle
has already reachedSTARTED
. (b/165435866)
Documentation Updated
ContextAware
documentation links toLifecycleOwner
to highlightLifecycle
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 implementsContextAware
, allowing you to add one or moreOnContextAvailableListener
instances which will receive a callback before the baseActivity.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 theFragmentManager
. Any listeners added to subclasses ofFragmentActivity
will run after that listener. (I513da) - This API is used by
AppCompatActivity
in AppCompat 1.3.0-alpha02. Any listeners added to subclasses ofAppCompatActivity
will run after that listener. (I513da)
- A suspending Kotlin extension
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 Fragment1.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 theRequestPermission
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 therequestCode
andintent
. (b/157212935) ActivityResultLauncher
now allows you to get theActivityResultContract
that was used to register the launcher. (b/156875743)
API Changes
- Breaking change: The
invoke()
method onActivityResultRegistry
has been renamed toonLaunch()
. (b/157496491) - The
OpenMultipleDocuments
contract now returns an empty list instead ofnull
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
- Added support for
ViewTreeViewModelStoreOwner
from Lifecycle2.3.0-alpha03
, andViewTreeSavedStateRegistryOwner
from SavedState1.1.0-alpha01
when using aView
within aComponentActivity
. (aosp/1297993, aosp/1300264)
API Changes
- The
TakePicture
contract now returns aboolean
indicating success rather than a thumbnailBitmap
as this was very rarely supported by camera apps when writing the image to the providedUri
. (b/154302879) - The
invoke()
extensions onActivityResultLauncher
have been removed in favor of explicitly usinglaunch()
to better indicate that these are asynchronous operations. Kotlin extensions forlaunch
have been added to theandroidx.activity.result
package forActivityResultLauncher<Void>
andActivityResultLauncher<Unit>
that remove the need to pass innull
orUnit
, respectively, mirroring that behavior from the previouslyinvoke()
extensions. (aosp/1304674, aosp/1304675) - The
IntentSenderRequest.Builder
methods forsetFlagsMask()
andsetFlagsValues()
has been combined into a singlesetFlags()
method. (aosp/1302111)
Bug Fixes
- When registering an
ActivityResultCallback
with aLifecycleOwner
, fixed an issue where the callback would be triggered before the state reachesSTARTED
. (aosp/1309744)
Behavior Changes
- The
ActivityResultRegistry
now generates request codes starting at0xFFFF
rather than at0
, preventing overlap when usingstartActivityForResult()
orrequestPermissions()
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 toregisterForActivityResult()
, both onComponentActivity
here and in Fragment1.3.0-alpha04
. (aosp/1278717) - The
GetContents
,OpenDocuments
, andRequestPermissions
contracts have been renamed toGetMultipleContents
,OpenMultipleDocuments
, andRequestMultiplePermissions
, respectively. (aosp/1280161) ComponentActivity
now implements theActivityResultRegisteryOwner
interface. (aosp/1290888)- - The
startActivityForResult()
/onActivityResult()
andonRequestPermissionsResult()
APIs onComponentActivity
have been deprecated. Please use the Activity Result APIs. (b/154751887)
Bug Fixes
- When using the
GetMultipleContents
andOpenMultipleDocuments
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
, andCreateDocument
contracts to the set of pre-built contracts provided byActivityResultContracts
. (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 aUri
input for where the image should be stored. The previous contract that does not take any input has been renamed toTakePicturePreview
. (aosp/1262482) - The
registerActivityResultCallback()
method onActivityResultRegistry
has been renamed toregister()
. (aosp/1267621) - The
dispose()
method onActivityResultLauncher
has been renamed tounregister()
and theunregisterResultCallback()
onActivityResultRegistry
has been removed. (aosp/1267621) - The
createIntent()
method ofActivityResultContact
now takes aContext
in addition to the input to make it possible to create explicit Intents. (aosp/1238800) - An
ActivityResultContract
can now overridegetSynchronousResult()
to deliver a result without callingstartActivityForResult
. This is used by theRequestPermission
andRequestPermissions
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 thatIntent
is not meant to be used withstartActivityForResult()
. (aosp/1266916) - Many of the Activity Result APIs not meant to be extended are now
final
. This includesgetActivityResultRegistry()
, theprepareCall()
methods, all methods ofActivityResultRegistry
exceptinvoke()
, and a number of the default contracts that do not support optional extras. (b/152439361)
Bug Fixes
- Fixed a
NullPointerException
inActivityResultRegistry
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 anActivityResultRegistry
that lets you handle thestartActivityForResult()
+onActivityResult()
as well asrequestPermissions()
+onRequestPermissionsResult()
flows without overriding methods in your Activity or Fragment, brings increased type safety viaActivityResultContract
, 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 Lifecycle2.3.0-alpha01
such that it will return the Activity as theLifecycleOwner
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 whereonBackPressed()
would cause anIllegalStateException
due to a bug in theandroid.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 usingby viewModels()
, theViewModelProvider
constructor, orViewModelProviders.of()
with aComponentActivity
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 SavedState1.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
- Activity now depends on Lifecycle
2.2.0-alpha04
.
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 usingby viewModels()
, theViewModelProvider
constructor, orViewModelProviders.of()
with aComponentActivity
(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 Lifecycle2.2.0-alpha02
. (aosp/1007817)activity-ktx
added a dependency onlifecycle-runtime-ktx
; you no longer need to explicitly add it to your dependencies when usingactivity-ktx
or libraries that depend onactivity-ktx
(such asfragment-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 forFragmentActivity
in Fragment1.1.0
and, by extension,AppCompatActivity
in AppCompat1.1.0
. - activity-ktx: The
activity-ktx
module includes aby viewModels
Kotlin property extension for accessing ViewModels. This module is automatically included when you includefragment-ktx
from Fragment1.1.0
. - OnBackPressedDispatcher: As a composable alternative to overriding
onBackPressed()
, you can now register aOnBackPressedCallback
from anyLifecycleOwner
(such as a fragment) to intercept system back button events. A lambda with receiver versionaddCallback
has been added toactivity-ktx
. See Provide custom back navigation documentation for more details. - onRetainCustomNonConfigurationInstance deprecation: the
onRetainCustomNonConfigurationInstance()
and the relatedgetLastCustomNonConfigurationInstance()
APIs have been deprecated. It is strongly recommended to use ViewModels to store non-configuration state as they offer a composable solution suitable for anyViewModelStoreOwner
that makes the ownership of the retained objects clear and provides anonCleared()
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
andremoveOnBackPressedCallback
methods onComponentActivity
have been removed. aosp/953857 - The
setEnabled()
andisEnabled()
methods ofOnBackPressedCallback
are now final. b/131416833 - The
remove()
method ofOnBackPressedCallback
is now final. aosp/952720 OnBackPressedDispatcher
now has public constructors, allowing you to construct your own instances for testing, etc. aosp/953431onBackPressed()
forComponentActivity
is now explicitly marked as@MainThread
aosp/952721
Bug fixes
- Fixed a
ConcurrentModificationException
when callingremove()
from within thehandleOnBackPressed()
method of aOnBackPressedCalback
that was added with aLifecycleOwner
. 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
andOnBackPressedDispatcher
have been marked as@MainThread
. (aosp/943813) - The
handleOnBackPressed()
method no longer returns aboolean
. Instead,OnBackPressedCallback
is now an abstract class that can be enabled or disabled - only when the newisEnabled()
method returns true willhandleOnBackPressed()
be called, in which you must handle the back button. (aosp/944518) - The
addCallback
methods ofOnBackPressedDispatcher
no longer return aCancellable
instance.OnBackPressedCallback
now contain aremove()
method that fulfill this functionality, allowing you to callremove()
duringhandleOnBackPressed()
. (aosp/944519) (aosp/946316) activity-ktx
now contains a receiver scoped callback foraddCallback
that accepts a lamdba that implementshandleOnBackPressed()
and has access toisEnabled
andremove()
(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 newOnBackPressedDispatcher
, retrievable viagetOnBackPressedDispatcher()
. (aosp/922523) - Methods to add a new
OnBackPressedCallback
to theOnBackPressedDispatcher
now return aCancellable
object, allowing removal of the callback without requiring an explicit reference to theOnBackPressedDispatcher
. (aosp/922523) - Adding a
OnBackPressedCallback
with an associatedLifecycleOwner
now results in adding and removing theOnBackPressedCallback
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-alpha04
and 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 usingsetContentView()
. (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 theactivity-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 madefinal
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
viaaddOnBackPressedCallback
to receiveonBackPressed()
callbacks without needing to override the method in your activity. - Added a new
by viewModels()
Kotlin property delegate for retrievingViewModel
s from aComponentActivity
. - Pending input events (such as clicks) are now canceled in
onStop()
.
API changes
- The implementation of
LifecycleOwner
andViewModelStoreOwner
have been moved fromFragmentActivity
toComponentActivity
. onRetainCustomNonConfigurationInstance
has been deprecated. Use aViewModel
for storing objects that need to survive configuration changes.