2022-01-26
Activity: v1.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
ComponentActivitynow integrates with ViewModel CreationExtras, introduced as part of Lifecycle2.5.0-alpha01. (Ie7e00, b/207012584)- Added
ComponentDialog, a subclass ofDialogthat includes anOnBackPressedDispatcherthat will be called when the system back button is pressed when the dialog is visible. Importantly, this subclass also sets theViewTreeOnBackPressedDispatcherOwner, allowing views a generic way to retrieve the correct dispatcher whether it exists in aComponentActivityor aComponentDialog. (I8a1bc) ComponentActivitynow implements the newOnNewIntentProviderinterface to allow any component to receive these events. (If1f8b)ComponentActivitynow implements the newOnConfigurationChangedProviderinterface to allow any component to receive these events. (If623b)ComponentActivitynow implements the newOnTrimMemoryProviderinterface to allow any component to receive these events. (Ia9295)
API Changes
- The no parameter constructor for
ActivityResultContracts.CreateDocumenthas been deprecated and replaced with a new constructor that takes a concrete mime type (e.g.,"image/png") as is required byIntent.ACTION_CREATE_DOCUMENT. (I2bec6) - The
OnBackPressedDispatcherOwnerassociated with a View can now be retrieved via theViewTreeOnBackPressedDispatcherOwner, rather than relying on casting theContext. (I74685)
Bug Fixes
- Fixed a crash when accessing a
ViewModelfor the very first time from aregisterForActivityResult()callback or the callbacks to aLifecycleObserveradded as part ofinitof aComponentActivity. (Ife83f)
Benchmark: v1.1.0-beta02
January 26, 2022
androidx.benchmark:benchmark-*:1.1.0-beta02 is released. Version 1.1.0-beta02 contains these commits.
Bug Fixes
- Microbenchmark Stack Sampling / Method Tracing Profile results are now linked in Studio output, similar to other profiling outputs, and do not suppress the allocation metric. (Idcb65, b/214440748, b/214253245)
- BaselineProfileRule now prints the
adb pullcommand in logcat and Studio output for pulling generated BaselineProfile text file. (f08811)
Camera-Camera2, Camera-Core, Camera-Lifecycle, & Camera-Video: v1.1.0-beta01
January 26, 2022
androidx.camera:camera-*:1.1.0-beta01 is released. Version 1.1.0-beta01 contains these commits.
New Features
- From 1.1.0-beta01, all CameraX libraries will align the same version number. This will help developers track versions much easier and reduce the complexity of large version compatibility matrix.
API Changes
- Added
Camera2CameraControl.clearCaptureRequestOptionsfor clearing the existing capture request options. (Ifa07d)
Bug Fixes
- Fixed the crash when recording the video on some pre-Android O(API 26) devices. (I88fdf, b/212328261)
- Fixed the incorrect AF region issue when using
cameraControl#startFocusAndMetering()on front lens-facing camera in Samsung devices (Ifbf59, b/210548792) - Use torch as flash on Pixel 3a/Pixel 3a XL to improve the speed and the captured image quality in dark (Ib12b6, b/211474332)
- Enabled applications to resume the camera when camera is interrupted by other higher priority application in the multi-window mode and the focus changes back to the application. Please note that there could be some latency(1 second to 10 seconds or more) between focus changes and camera reopened due to some framework issue. (I4d092)
Car App: v1.2.0-beta02
January 26, 2022
androidx.car.app:app-*:1.2.0-beta02 is released. Version 1.2.0-beta02 contains these commits.
Car apps built with this library version targeting the Android Automotive OS platform can now be published to the Play Store open testing channel. Refer to the development guide for more details.
Features annotated with API level 4 and under are compatible with both Android Auto 7.2+ and the new Android Automotive OS platform. See the Known Issues section below for caveats.
API Changes
- Added experimental
setOnContentRefreshListenerAPI to POI templates (I6bf22)
Bug Fixes
- Fixed a memory leak in
CarAppServicewhen the car host unbinds. (I5c9ca, b/203594731) - Updated
CarAppActivityjavadoc to include requirements for singleTask launchmode (Id2f95) - Reduces the visual glitch on resume. (Iff7e0)
Known Issue(s)
- The map
ActionStrips in thePlaceListNavigationTemplateandRoutePreviewNavigateTemplatewill start becoming available in the nextAndroid AutoandAndroid Automotive OSreleases.
Compose Animation: v1.1.0-rc03
January 26, 2022
androidx.compose.animation:animation:1.1.0-rc03, androidx.compose.animation:animation-core:1.1.0-rc03, and androidx.compose.animation:animation-graphics:1.1.0-rc03 are released. Version 1.1.0-rc03 contains these commits.
Bug Fixes
- Updated to support Compose Material 1.1.0-rc03
Compose Compiler: v1.1.0-rc03
January 26, 2022
androidx.compose.compiler:compiler:1.1.0-rc03 is released. Version 1.1.0-rc03 contains these commits.
Bug Fixes
- Updated to support Compose Material 1.1.0-rc03
Compose Foundation: v1.1.0-rc03
January 26, 2022
androidx.compose.foundation:foundation:1.1.0-rc03 and androidx.compose.foundation:foundation-layout:1.1.0-rc03 are released. Version 1.1.0-rc03 contains these commits.
Bug Fixes
- Updated to support Compose Material 1.1.0-rc03
Compose Material: v1.1.0-rc03
January 26, 2022
androidx.compose.material:material-*:1.1.0-rc03 is released. Version 1.1.0-rc03 contains these commits.
Behaviour Changes
Note that, with respect to Compose 1.0, Material components will expand their layout space to meet Material accessibility guidelines touch target size. For instance, Button touch target will expand to a minimum size of 48x48dp, even if you set the Button's size to be smaller. This aligns Compose Material to the same behavior of Material Design Components, providing consistent behavior if you mix Views and Compose. This change also ensures that when you create your UI using Compose Material components, minimum requirements for touch target accessibility will be met.
Bug Fixes
- Added some better debug information for the layout inspector when inspecting minimum touch target modifiers. (aosp/1955036)
Compose Runtime: v1.1.0-rc03
January 26, 2022
androidx.compose.runtime:runtime-*:1.1.0-rc03 is released. Version 1.1.0-rc03 contains these commits.
Bug Fixes
- Updated to support Compose Material 1.1.0-rc03
Compose UI: v1.1.0-rc03
January 26, 2022
androidx.compose.ui:ui-*:1.1.0-rc03 is released. Version 1.1.0-rc03 contains these commits.
Bug Fixes
- Updated to support Compose Material 1.1.0-rc03
Compose Animation: v1.2.0-alpha02
January 26, 2022
androidx.compose.animation:animation:1.2.0-alpha02, androidx.compose.animation:animation-core:1.2.0-alpha02, and androidx.compose.animation:animation-graphics:1.2.0-alpha02 are released. Version 1.2.0-alpha02 contains these commits.
Compose Compiler: v1.2.0-alpha02
January 26, 2022
androidx.compose.compiler:compiler:1.2.0-alpha02 is released. Version 1.2.0-alpha02 contains these commits.
Compose Foundation: v1.2.0-alpha02
January 26, 2022
androidx.compose.foundation:foundation:1.2.0-alpha02 and androidx.compose.foundation:foundation-layout:1.2.0-alpha02 are released. Version 1.2.0-alpha02 contains these commits.
API Changes
- Added
NonRestartableComposableto methods that are overloads of existing methods without complex logic. This reduces compiler generated memoization checks (equals) for all parameters which are repeated in the inner function that is called. (I90490) - Added
excludeFromSystemGestureModifiers for easy access to Android'ssetSystemGestureExclusionRects(I46f07)
Bug Fixes
- Text selection magnifier behavior has been polished to match the platform magnifier. (Idd918, b/206833278)
LazyColumn,LazyRow,Modifier.verticalScrolland other containers that useModifier.scrollablenow support mouse wheel scrolling. (I2b5e1, b/198214718)
Compose Material: v1.2.0-alpha02
January 26, 2022
androidx.compose.material:material-*:1.2.0-alpha02 is released. Version 1.2.0-alpha02 contains these commits.
API Changes
- Added
NonRestartableComposableto methods that are overloads of existing methods without complex logic. This reduces compiler generated memoization checks (equals) for all parameters which are repeated in the inner function that is called. (I90490) - Add support for action chip (I07100, b/192585545)
Compose Material 3: v1.0.0-alpha04
January 26, 2022
androidx.compose.material3:material3:1.0.0-alpha04 is released. Version 1.0.0-alpha04 contains these commits.
API Changes
- Added
NonRestartableComposableto methods that are overloads of existing methods without complex logic. This reduces compiler generated memoization checks (equals) for all parameters which are repeated in the inner function that is called. (I90490) - Added Material 3 divider. (Ica5fc)
- Mark the Checkbox and RadioButton with an experimental API annotation. (Ie44bb)
- Added support for Material 3 progress indicators. (Iff232, b/205023841)
Bug Fixes
- Update a disabled
TextButton'scontainer color to be transparent (I6b248, b/213339737)
Compose Runtime: v1.2.0-alpha02
January 26, 2022
androidx.compose.runtime:runtime-*:1.2.0-alpha02 is released. Version 1.2.0-alpha02 contains these commits.
Compose UI: v1.2.0-alpha02
January 26, 2022
androidx.compose.ui:ui-*:1.2.0-alpha02 is released. Version 1.2.0-alpha02 contains these commits.
API Changes
- Added
Modifier.onRotaryScrollEvent()andModifier.onPreRotaryScrollEvent()for wear devices with a rotating side button (I18bf5, b/210748686) - Add experimental
View.createLifecycleAwareRecomposerextension (I0cde6)
External Contribution
PointerEvent.scrollDelta.yis now inverted on Android (now it returns 1 instead of -1 if we tilt mouse wheel to the right) (Ia9811)
Core and Core-ktx: v1.8.0-alpha03
January 26, 2022
androidx.core:core:1.8.0-alpha03 and androidx.core:core-ktx:1.8.0-alpha03 are released. Version 1.8.0-alpha03 contains these commits.
API Changes
- Converted
WindowInsetsControllerCompatto depend on a View instead of a Window or the platformWindowInsetsController. This improves behavior with Dialogs, showing the IME, and ensures the non-deprecated creation methods workaround (b/180881870). (I29264, b/207401542, b/210121779) - Cleaned up nullability for a subset of androidx.core APIs. (Ib2583, b/206113818)
- Fixed nullability of
performAccessibilityActionparams (Ibbafe) - Added method for working around
ColorStateListissues resulting from Theme-keyed caching and Theme.applyStyle (I9188b, b/207739887) - Update shortcut visibility api for better readability (Ia58df)
- Added zero-arg overload for
persistableBundleOf()to avoid an unnecessary array allocation when creating an empty PersistableBundle (Icd7a4)
Core Remote Views: v1.0.0-alpha02
January 26, 2022
androidx.core:core-remoteviews:1.0.0-alpha02 is released. Version 1.0.0-alpha02 contains these commits.
DragAndDrop: v1.0.0-alpha03
January 26, 2022
androidx.draganddrop:draganddrop:1.0.0-alpha03 is released. Version 1.0.0-alpha03 contains these commits.
New Features
- On devices running Android S or later,
DropHelpernow delegates to the system implementation ofOnReceiveContentListener, automatically providing support for input methods other than drag and drop.
Emoji2: v1.1.0-beta01
January 26, 2022
androidx.emoji2:emoji2-*:1.1.0-beta01 is released. Version 1.1.0-beta01 contains these commits.
Bug Fixes
- androidx-emoji2 beta01 release. No changes from alpha01 (Ic61d9)
Fragment: v1.4.1
January 26, 2022
androidx.fragment:fragment:1.4.1, androidx.fragment:fragment-ktx:1.4.1, and androidx.fragment:fragment-testing:1.4.1 are released. Version 1.4.1 contains these commits.
Bug Fixes
FragmentContainerViewno longer throws an illegal state exception when view IDs generated from xml have negative values. (Ic185b, b/213086140)- When using a custom
ownerProducerlambda with theby viewModels()lazy function, it will now use thedefaultViewModelProviderFactoryfrom that owner if a customViewModelProvider.Factoryis not provided instead of always using the fragment's factory. (I56170, b/214106513)
Fragment: v1.5.0-alpha01
January 26, 2022
androidx.fragment:fragment:1.5.0-alpha01, androidx.fragment:fragment-ktx:1.5.0-alpha01, and androidx.fragment:fragment-testing:1.5.0-alpha01 are released. Version 1.5.0-alpha01 contains these commits.
New Features
Fragmentnow integrates with ViewModel CreationExtras, introduced as part of Lifecycle2.5.0-alpha01. (I3060b, b/207012585)
Bug Fixes
- From Fragment
1.4.1:FragmentContainerViewno longer throws an illegal state exception when view IDs generated from xml have negative values. (Ic185b, b/213086140) - From Fragment
1.4.1: When using a customownerProducerlambda with theby viewModels()lazy function, it will now use thedefaultViewModelProviderFactoryfrom that owner if a customViewModelProvider.Factoryis not provided instead of always using the fragment's factory. (I56170, b/214106513) - Fixed a crash when accessing a
ViewModelfor the very first time from aregisterForActivityResult()callback of aFragment. (Iea2b3)
Games-Activity: v1.1.0-beta03
January 26, 2022
androidx.games:games-activity:1.1.0-beta03 is released. Version 1.1.0-beta03 contains these commits.
Bug Fixes
- Fix signature of
onNativeWindowResized - Maintain handle to native window in
onSurfaceChanged
Games-Controller: v1.1.0-beta01
January 26, 2022
androidx.games:games-controller:1.1.0-beta01 is released with no changes since 1.1.0-alpha01. Version 1.1.0-beta01 contains these commits.
Games Frame Pacing 1.10: v1.10.0-beta01
January 26, 2022
androidx.games:games-frame-pacing:1.10.0-beta01 is released. Version 1.10.0-beta01 contains these commits.
Games Performance Tuner 1.5.0: v1.5.0-rc01
January 26, 2022
androidx.games:games-performance-tuner:1.5.0-rc01 is released. Version 1.5.0-rc01 contains these commits.
Bug Fixes
- Fix for memory corruption in API key on API<=23
Games-Text-Input: v1.1.0-rc01
January 26, 2022
androidx.games:games-text-input:1.1.0-rc01 is released. Version 1.1.0-rc01 contains these commits.
Glance: v1.0.0-alpha02
January 26, 2022
androidx.glance:glance-*:1.0.0-alpha02 is released. Version 1.0.0-alpha02 contains these commits.
New Features
This release contains the set of APIs to build Wear Tiles using Compose runtime with composables optimized for "Glanceable"
- Declare your wear tile service by extending
GlanceTileService, a service to create your tile in the composable Content() function. - Wear tiles specific glance composables:
CurvedRow,CurvedText. - Handle different timeline modes for tile by defining
TimelineMode.SingleEntryandTimelineMode.TimeBoundEntries. LocalTimeInterval, the Local composition refer to a specific time interval.BorderModiferis aGlanceModifierapplying a border around an element.
This release also adds Progress Indicators to AppWidget Glance.
API Changes
- Added
LinearProgressIndicatorandCircularProgressIndicatorcomposable. (Ie116b) - Change
actionStartBroadcastReceivertoactionSendBroadcast(I7d555) - Pass Context to
GlanceAppWidgetonDelete callback (I4c795)
Bug Fixes
- Correct handling of OPTIONS_APPWIDGET_SIZES if present but empty. (I01f82)
Hilt-Navigation-Compose: v1.0.0
January 26, 2022
androidx.hilt:hilt-navigation-compose:1.0.0 is released. Version 1.0.0 contains these commits.
Major features of 1.0.0
The androidx.hilt:hilt-navigation-compose artifact provides APIs that allow users to get a @HiltViewModel annotated ViewModel from a Navigation back stack entry within a Compose application using :navigation-compose.
The function hiltViewModel() returns an existing ViewModel or creates a new one scoped to the current navigation graph present on the NavController back stack. The function can optionally take a NavBackStackEntry to scope the ViewModel to a parent back stack entry.
Lifecycle: v2.5.0-alpha01
January 26, 2022
androidx.lifecycle:lifecycle-*:2.5.0-alpha01 is released. Version 2.5.0-alpha01 contains these commits.
ViewModel CreationExtras
With this release, we are laying the groundwork for restructuring how a ViewModel is constructed. Instead of a rigid set of subclasses of ViewModelProvider.Factory that each add additional functionality (allowing an Application constructor parameter via AndroidViewModelFactory, allowing a SavedStateHandle constructor parameter via SavedStateViewModelFactory and AbstractSavedStateViewModelFactory, etc.), we are moving to a world of stateless factories that rely on a new concept, CreationExtras. (Ia7343, b/188691010, b/188541057)
With this change, ViewModelProvider no longer makes direct calls into the previous create(Class<T>) method of ViewModelProvider.Factory. Instead, it calls into a new overload of create: create(Class<T>, CreationExtras). This means that any direct implementation of the ViewModelProvider.Factory instance now has access to each of these new CreationExtras:
ViewModelProvider.NewInstanceFactory.VIEW_MODEL_KEY: thisStringprovides access to the custom key you passed toViewModelProvider.get().ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEYprovides access to theApplicationclass.SavedStateHandleSupport.SAVED_STATE_REGISTRY_OWNER_KEYprovides access to theSavedStateRegistryOwnerthat is being used to construct this ViewModel.SavedStateHandleSupport.VIEW_MODEL_STORE_OWNER_KEYprovides access to theViewModelStoreOwnerthat is being used to construct this ViewModel.SavedStateHandleSupport.DEFAULT_ARGS_KEYprovides access to theBundleof arguments that should be used to construct aSavedStateHandle.
These extras are provided by default when using Activity 1.5.0-alpha01, Fragment 1.5.0-alpha01, and Navigation 2.5.0-alpha01. If you use an earlier version of those libraries, your CreationExtras will be empty - all of the existing subclasses of ViewModelProvider.Factory have been rewritten to support both the legacy creation path used by earlier versions of those libraries and the CreationExtras path which will be used going forward.
These CreationExtras allow you to construct a ViewModelProvider.Factory that passes just the information you need to each ViewModel without relying on a strict hierarchy of Factory subclasses:
class CustomFactory : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
return when (modelClass) {
HomeViewModel::class -> {
// Get the Application object from extras
val application = checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY])
// Pass it directly to HomeViewModel
HomeViewModel(application)
}
DetailViewModel::class -> {
// Create a SavedStateHandle for this ViewModel from extras
val savedStateHandle = extras.createSavedStateHandle()
DetailViewModel(savedStateHandle)
}
else -> throw IllegalArgumentException("Unknown class $modelClass")
} as T
}
}
We use the createSavedStateHandle() Kotlin extension function on CreationExtras from SavedStateHandleSupport to construct a SavedStateHandle only for the one ViewModel that needs it. (Ia6654, b/188541057)
Custom CreationExtras can be provided by overriding getDefaultViewModelCreationExtras() in your ComponentActivity or Fragment, thus making them available to your custom ViewModelProvider.Factory as a built in form of assisted injection. These extras will automatically be made available to your custom Factory when used directly with ViewModelProvider or when using the by viewModels() and by activityViewModels() Kotlin property extensions. (I79f2b, b/207012584, b/207012585, b/207012490)
Bug Fixes
- Fixed an issue where the default value provided to a
SavedStateHandlewould reappear after process death and recreation, even if it was specifically removed from theSavedStateHandle. As a consequence of this,SavedStateHandlewill no longer merge default values and restored values together, instead only using the restored values as the source of truth. (I53a4b)
Media: v1.5.0-rc01
January 26, 2022
androidx.media:media:1.5.0-rc01 is released with no changes since 1.5.0-beta01. Version 1.5.0-rc01 contains these commits.
Mediarouter: v1.2.6
January 26, 2022
androidx.mediarouter:mediarouter:1.2.6 is released. Version 1.2.6 contains these commits.
Bug Fixes
- Fix
RemotePlaybackClientconstructor crash on Android 12 b/210684559
Navigation: v2.5.0-alpha01
January 26, 2022
androidx.navigation:navigation-*:2.5.0-alpha01 is released. Version 2.5.0-alpha01 contains these commits.
New Features
NavBackStackEntrynow integrates with ViewModel CreationExtras, introduced as part of Lifecycle2.5.0-alpha01. (Ib9fe2, b/207012490)
Bug Fixes
- Fixed an issue where accessing a
ViewModelcreated viaby navGraphViewModels()from a Fragment'sonCreate()would fail with anIllegalStateException. (I8a14d) NavDeepLinks will no longer unnecessarily decode args twice, meaning that the proper args are now passed to your final destination. (I31b0a, b/210711399)
Safe Args
- Safe Args now depends on Android Gradle Plugin version 7.0.4. This means that Navigation Safe Args will no longer be compatible with Android Studio versions prior to 7.0, but is now compatible with Android Gradle Plugin 7.1.0 and higher. (I41c88, b/213086135, b/207670704)
Navigation: v2.4.0
January 26, 2022
androidx.navigation:navigation-*:2.4.0 is released. Version 2.4.0 contains these commits.
Important changes since 2.3.0
- All Navigation artifacts have been rewritten in Kotlin. This has improved the nullability of classes using generics (such as
NavTypesubclasses). All Kotlin extension functions that used to be part of the-ktxartifacts have been moved to their respective main artifacts. The-ktxartifacts will continue to be published, but are completely empty. - The
navigation-fragmentartifact now contains a prebuilt implementation of a two pane layout via the newAbstractListDetailFragment. This fragment uses aSlidingPaneLayoutto manage a list pane (which your subclass provides) and a detail pane, which uses aNavHostFragmentas its implementation, as seen in our example implementation. - The
currentBackStackEntryAsFlow()method onNavControllerprovides aFlowthat emits whenever the currentNavBackStackEntrychanges. This flow can be used as an alternative to manually managing anOnDestinationChangedListener. - NavController now offers the ability to retrieve a list of all visible
NavBackStackEntryinstances as aStateFlowvia the experimentalvisibleEntriesproperty. - It is now possible to extend the
NavTypeclass to create custom NavTypes. Custom types are supported only when building your navigation graph programmatically, such as via the Navigation Graph Kotlin DSL. Navigation now provides
findStartDestination()andgetHierarchy()APIs that can be used to help implement custom NavigationUI.findStartDestination()is an extension function onNavGraphthat will locate the actual start destination that will be displayed when you navigate to the graph, even if thestartDestinationis itself a nestedNavGraph.getHierarchy()is a function onNavDestinationthat can be used to verify if a given destination is within the hierarchy of another.val matchingRoute: Boolean = destination.hierarchy.any { it.route == routeToFind }NavigationUImethods that took aBottomNavigationViewhave been updated to instead take its superclass introduced in Material1.4.0,NavigationBarView. This allows these methods to be used with theNavigationRailView.When inflating an
<action>element via XML, animation attributes can use attributes pulled from your theme using theapp:enterAnim="?attr/transitionEnter"syntax.Safe Args now generates a
fromSavedStateHandle()method for eachNavArgsclass. (#122, b/136967621)class HomeViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { // Create a HomeDestinationArgs class with type safe accessors for each argument // defined on your destination private val args = HomeDestinationArgs.fromSavedStateHandle(savedStateHandle) }
Navigation Routes and the Kotlin DSL
Previous versions of Navigation relied on each destination having a constant integer ID that would uniquely identify it from its sibling destinations and allow you to navigate() to that destination either directly or via an action. While this continues to be valid and useful, particularly in cases where you are defining your navigation graph in XML and can use auto-generated R.id constants or Safe Args (which uses those constants to generate code at build time), this system of unique integers did not capture the semantic meaning and expressiveness needed to support fully dynamic graphs built programmatically at runtime via the Navigation Kotlin DSL.
This release introduces a new option for uniquely identifying a destination in a navigation graph by its route. A route is a String that defines the unique path to a destination. All Kotlin DSL methods that took a destination ID are now deprecated and replaced with an equivalent API that takes a route.
Each route should be treated as the ‘path’ part of a Uri that defines that destination, e.g., home, profile/{userId}, profile/{userId}/friends, etc. When the identity of a destination is associated with a specific piece of content, those dynamic arguments should be part of the route, following the same rules as implicit deep links.
All NavController APIs that used to only take an ID now have an overload that takes a route String. This includes navigate(), popBackStack(), popUpTo(), and getBackStackEntry().
This has had some API implications:
- The
popUpToKotlin property on the Kotlin DSL has been deprecated in favor ofpopUpToId. - The
getStartDestination()API has been deprecated in favor ofgetStartDestinationId().
Unlike when navigating by ID, navigating by route follows the same rules as implicit deep links in that you can directly navigate to any destination in any nested graph, ensuring that these routes are usable in multi-module projects without explicitly adding an externally visible deep link to each destination.
Navigation Compose
The navigation-compose artifact provides integration between the Navigation Component and Jetpack Compose. It uses @Composable functions as the destinations in your application.
This release provides:
- A
NavHostcomposable that allows you to construct your navigation graph via a Kotlin DSL, usingcomposableanddialogdestinations, plus support for optional Navigators such as those from Accompanist Navigation Material. - Mandatory support for crossfading between destinations. Accompanist Navigation Animation can be used to control the enter and exit transitions using experimental Compose APIs.
- Scoping of a
Lifecycleto each composable destination. Each destination only reaches theRESUMEDstate when any entering transitions finish and immediately drops toSTARTEDwhen any exiting transitions start, thus allowing you to avoid allIllegalStateExceptionand multi-touch issues by only triggering anavigatecall when theLifecycleisRESUMED. - Scoping of
ViewModel(via theviewModel()API of Lifecycle ViewModel Compose2.4.0orhiltViewModel()of Hilt Navigation Compose1.0.0at the destination level, providing a scope that survives configuration changes and being on the back stack (when your Composable content is otherwise disposed) and a signal in the ViewModel’sonCleared()that indicates the permanent disposal and cleaning up of state associated with thatNavBackStackEntry. - Scoping of
rememberSaveablestate at a destination level, ensuring that all composable state is saved and restored automatically when you return to a destination. - Full support for saving and restoring the state of the
NavControllerand its destination’s state after process death and recreation. - Automatic integration with the system back button.
Support for passing arguments, attaching deep links to destinations, and returning a result to previous destinations.
Compose specific helpers in
rememberNavController()andcurrentBackStackEntryAsState()to allow hoisting state and connecting theNavControllerto composables outside of theNavHost(such as a bottom navigation bar).
val navController = rememberNavController()
Scaffold { innerPadding ->
NavHost(navController, "home", Modifier.padding(innerPadding)) {
composable("home") {
// This content fills the area provided to the NavHost
HomeScreen()
}
dialog("detail_dialog") {
// This content will be automatically added to a Dialog() composable
// and appear above the HomeScreen or other composable destinations
DetailDialogContent()
}
}
}
See the Compose Navigation guide for more information.
Multiple back stacks
The NavController is responsible for managing the back stack of destinations, adding destinations to the back stack when you navigate() to them and removing them when you call popBackStack() or trigger the system back button. The existing NavOptions class and the integration into <action> elements in the navigation graph XML has been expanded to support saving and restoring the back stack.
As part of this change, the NavigationUI methods of onNavDestinationSelected(), BottomNavigationView.setupWithNavController() and NavigationView.setupWithNavController() now automatically save and restore the state of popped destinations, enabling support for multiple back stacks without any code changes. When using Navigation with Fragments, this is the recommended way to integrate with multiple back stacks.
The underlying APIs for saving and restoring the state are exposed via a number of surfaces:
In Navigation XML, the
<action>element can now use the boolean attributes ofapp:popUpToSaveStateandapp:restoreStateto save the state of any destinations popped viaapp:popUpToand restore the state associated with the destination passed as theapp:destination:<action android:id=”@+id/swap_stack” app:destination=”@id/second_stack” app:restoreState=”true” app:popUpTo=”@id/first_stack_start_destination” app:popUpToSaveState=”true” />In the
navOptionsKotlin DSL, you can add therestoreStateboolean property and thesaveStateboolean property on thepopUpTobuilder:// Use the navigate() method that takes a navOptions DSL Builder navController.navigate(selectedBottomNavRoute) { launchSingleTop = true restoreState = true popUpTo(navController.graph.findStartDestination().id) { saveState = true } }In manually building a
NavOptionsobject via theNavOptions.Builder, you can use thesetRestoreState()and new overload tosetPopUpTo()that takes an additionalsaveStateparameter.NavOptions navOptions = new NavOptions.Builder() .setLaunchSingleTop(true) .setRestoreState(true) .setPopUpTo(NavGraph.findStartDestination(navController.getGraph()).getId(), false, // inclusive true) // saveState .build(); navController.navigate(selectedBottomNavId, null, navOptions);Programmatic calls to
popBackStack()can now include an additionalsaveStateparameter.You can use the
clearBackStack()method to clear any state that was saved withpopBackStack()orpopUpToSaveState.
In all cases, the NavController will save and restore the state of each NavBackStackEntry, including any navigation destination scoped ViewModel instances. The Navigator APIs have been updated to enable each Navigator to support saving and restoring their own state.
Behavior changes
NavDeepLinkBuildernow addsPendingIntent.FLAG_IMMUTABLEto thePendingIntentreturned bycreatePendingIntent(), ensuring that this API works as expected when targeting Android 12.- Navigation now depends on Lifecycle
2.3.1and now markssetGraph(),popBackStack(),navigateUp(), andnavigate(), the methods that update theNavBackStackEntryLifecycle, as@MainThread, aligning Navigation with the main thread enforcement introduced in Lifecycle2.3.0. - Deep links now verify that all required arguments (those without default values) are present in the
Uri. NavDeepLinkparsed arguments now consider pound signs in the same way as question marks as a separator between path segments, preventing an argument from spanning across the pound sign.- When generating actions, Kotlin code generated from Safe Args now puts arguments without default values before those with default values as parameters.
- When generating arguments, Safe Args now puts parameters without default values before those with default values.
- Safe-Args now depends on Android Gradle Plugin 4.2.0. This means you should no longer get the using
applicationIdTextResourcewarning.
Known issues
- Fixed in Navigation
2.5.0-alpha01: accessing aViewModelcreated viaby navGraphViewModels()from a Fragment'sonCreate()will fail with anIllegalStateException. (b/213504272) - Fixed in Navigation
2.5.0-alpha01: Safe Args 2.4.0 is incompatible with Android Gradle Plugin 7.1.0 and higher. (b/213086135) - Deep linking with multiple nested nav graphs doesn't correctly create the full backstack. (b/(b/214383060)
Preference: v1.2.0
January 26, 2022
androidx.preference:preference:1.2.0 and androidx.preference:preference-ktx:1.2.0 are released. Version 1.2.0 contains these commits.
Important changes since 1.1.0
- Added
PreferenceHeaderFragmentCompatfor two-pane preference that automatically adapts based on size of the device used, making it suitable for use on phones, foldables, and tablets. The header pane is provided by overriding theonCreatePreferenceHeader()method onPreferenceHeaderFragmentCompat. Any<Preference>in the headerPreferenceFragmentCompatthat usesapp:fragmentwill cause that fragment to appear in the second detail pane. The initial detail fragment that should be displayed before any preference is manually selected can be customized by overridingonCreateInitialDetailFragment(). The default implementation returns the first preference that has a fragment defined on it.
class TwoPanePreference : PreferenceHeaderFragmentCompat() {
override fun onCreatePreferenceHeader(): PreferenceFragmentCompat {
return PreferenceHeader()
}
}
Added nullability annotations to many of the APIs that previously did not specify
@NonNullor@Nullable. This is a potentially Kotlin source breaking change if the nullability you had chosen in your Kotlin code did not match the nullability that is now defined.PreferenceFragmentCompat’s now looks for implementations of theOnPreferenceStartFragmentCallback,OnNavigateToScreenListener, andOnDisplayPreferenceDialogListenerinterface on parent fragments before looking to see if the hosting Context or Activity implement these interfaces.
ProfileInstaller: v1.2.0-alpha02
January 26, 2022
androidx.profileinstaller:profileinstaller:1.2.0-alpha02 is released. Version 1.2.0-alpha02 contains these commits.
This version is identical to 1.2.0-alpha01.
ResourceInspection: v1.0.1
January 26, 2022
androidx.resourceinspection:resourceinspection-annotation:1.0.1 and androidx.resourceinspection:resourceinspection-processor:1.0.1 are released. Version 1.0.1 contains these commits.
Bug Fixes
- Added package documentation
Savedstate: v1.2.0-alpha01
January 26, 2022
androidx.savedstate:savedstate:1.2.0-alpha01 and androidx.savedstate:savedstate-ktx:1.2.0-alpha01 are released. Version 1.2.0-alpha01 contains these commits.
New Features
SavedStateRegistryControllernow allows early attachment of theSavedStateRegistryviaperformAttach(). (Ice4bf)
Behavior Changes
SavedStateRegistryno longer saves an empty Bundle if there is no state to save. (aosp/1896865, b/203457956)
Slidingpanelayout: v1.2.0
January 26, 2022
androidx.slidingpanelayout:slidingpanelayout:1.2.0 is released. Version 1.2.0 contains these commits.
Important changes since 1.1.0
SlidingPaneLayoutis now fold-aware. On a foldable device,SlidingPaneLayoutwill automatically adjust the size of the two panes so that the panes are on either side of the fold, hinge, etc.- When handling your own configuration changes, -
SlidingPaneLayoutnow animates between the single pane and two pane modes when the amount of space provided changes (i.e., when unfolding a foldable device). SlidingPaneLayoutnow has a new UI styling when the two panes overlap. Each pane will now extend from edge to edge, with the detail or secondary pane fully covering the list or primary pane when theSlidingPaneLayoutis open. APIs specific to the old UI styling, such as the fade color, have been deprecated.SlidingPaneLayoutnow defaults to ‘closed’ - i.e., showing the list or primary pane. Callingopen()oropenPane()will now show the detail or secondary pane.- Improved compatibility with additional measure specs to ensure that
SlidingPaneLayoutcan be used in any type of layout without throwing anIllegalStateException. - SlidingPaneLayout now allows registering multiple PanelSlideListeners.
- Developers can now control whether users can swipe between the list and detail panes by setting a lock mode.
Wear Compose: v1.0.0-alpha15
January 26, 2022
androidx.wear.compose:compose-foundation:1.0.0-alpha15, androidx.wear.compose:compose-material:1.0.0-alpha15, and androidx.wear.compose:compose-navigation:1.0.0-alpha15 are released. Version 1.0.0-alpha15 contains these commits.
API Changes
- We have added a new property
autoCenteringto theScalingLazyColumn. When true (the default) this will ensure that all items including the first and last can be scrolled so that they are visible in the center of the lists viewport. Note that if using auto-centering you will probably want to set vertical content padding to 0.dp. If both autoCentering and vertical content padding are provided then they will both result in additional space being available before the first and after the last list items allowing them to be scrolled even further. (I2a282, b/214922490) - We have added a
Dialogcomponent that enables any composable to trigger a full screen dialog that sits on top of other content. When shown, the dialog supports swipe-to-dismiss and will show its parent's content in the background during the swipe gesture. The dialog content is expected to beAlertorConfirmation(renamed from earlier componentsAlertDialogandConfirmationDialog) -Alert,ConfirmationandDialogare all in theandroidx.wear.compose.material.dialogpackage. Alert and Confirmation can be used as navigation destinations. Also, added ColumnScope to Alert and Confirmation parameters as necessary. (Ia9014) - We have removed
onSurfaceVariant2from the Compose for WearOS Material Theme Colors and replaced uses in the library withonSurfaceVariant. (Icd592) - Added a method to programmatically select an option on the
PickerState, the initially selected option can now also be specified when creating aPickerState. (I92bdf) - We have added support for customizing the fling behavior of the
ScalingLazyColumn. (I1ad2e, b/208842968) - We have added
NavController.currentBackStackEntryAsState()to theWear.Compose.Navigationlibrary. (If9028, b/212739653) - Added
Modifier.onRotaryScrollEvent()andModifier.onPreRotaryScrollEvent()for Wear devices with a rotating side button.(I18bf5, b/210748686)
Wear Tiles: v1.1.0-alpha01
January 26, 2022
androidx.wear.tiles:tiles-*:1.1.0-alpha01 is released. Version 1.1.0-alpha01 contains these commits.
New Features
- The new library Tiles Material has been added. It contains components to build Tiles layouts faster and easier with Material design. Initial components are:
ButtonChipCompactChipTitleChip
Bug Fixes
- Fix bug in
TileUiClientwhich led to cached resources being discarded. (I60e0b)
Wear Tiles: v1.0.1
January 26, 2022
androidx.wear.tiles:tiles-*:1.0.1 is released. Version 1.0.1 contains these commits.
Bug Fixes
- Fix bug in
TileUiClientwhich led to cached resources being discarded. (I60e0b)
WindowManager: v1.0.0
January 26, 2022
androidx.window:window-*:1.0.0 is released. Version 1.0.0 contains these commits.
Major features of 1.0.0
- Support for folding phones through
WindowInfoTrackerandFoldingFeature.WindowMetricsCalculatorto help calculate the current WindowMetrics.