Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit e2ac3b6793a301fe493b4e657e9cf1a02c780887
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 18 23:02:22 2022
Call enableSavedStateHandles() immediately after performAttach()
Now that enableSavedStateHandles() no longer requires immediate
access to a ViewModel, we can safely call it immeidately after
performAttach().
Test: existing tests still pass
BUG: 215406268
Change-Id: I348ae5f95cb607e92e2f38bccc2b6d5b5876fb16
M navigation/navigation-common/build.gradle
M fragment/fragment/build.gradle
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M fragment/fragment-ktx/build.gradle
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M activity/activity-ktx/build.gradle
M activity/activity/build.gradle
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentViewLifecycleOwner.java
M navigation/navigation-common/src/main/java/androidx/navigation/NavBackStackEntry.kt
https://android-review.googlesource.com/2032475
Branch: androidx-main
commit e2ac3b6793a301fe493b4e657e9cf1a02c780887
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 18 23:02:22 2022
Call enableSavedStateHandles() immediately after performAttach()
Now that enableSavedStateHandles() no longer requires immediate
access to a ViewModel, we can safely call it immeidately after
performAttach().
Test: existing tests still pass
BUG: 215406268
Change-Id: I348ae5f95cb607e92e2f38bccc2b6d5b5876fb16
M navigation/navigation-common/build.gradle
M fragment/fragment/build.gradle
M activity/activity/src/main/java/androidx/activity/ComponentActivity.java
M fragment/fragment-ktx/build.gradle
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M activity/activity-ktx/build.gradle
M activity/activity/build.gradle
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentViewLifecycleOwner.java
M navigation/navigation-common/src/main/java/androidx/navigation/NavBackStackEntry.kt
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 29973ff449dbac17299da3c113017e01dbde09d8
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 18 22:16:45 2022
Remove dependency on ViewModels in enableSavedStateHandles()
Rather than requiring the creation of a ViewModel as part of
the call to enableSavedStateHandle(), defer that creation
until createSavedStateHandle() is actually called. This
ensures that enableSavedStateHandles() is safe to call before
the owner is attached to a Context, etc.
Relnote: "You can now retrieve a previously registered
`SavedStateProvider` from a `SavedStateRegistry` via
`getSavedStateProvider()`."
Test: updated tests
BUG: 215406268
Change-Id: I7ea470c1af0385b8bc9d8ca653c84cc8d224e6cf
M savedstate/savedstate/api/restricted_current.txt
M savedstate/savedstate/src/main/java/androidx/savedstate/SavedStateRegistry.java
M savedstate/savedstate/api/current.txt
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
M lifecycle/lifecycle-viewmodel-savedstate/src/main/java/androidx/lifecycle/SavedStateHandleSupport.kt
M lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/SavedStateHandleSupportTest.kt
M savedstate/savedstate/api/public_plus_experimental_current.txt
https://android-review.googlesource.com/2032091
Branch: androidx-main
commit 29973ff449dbac17299da3c113017e01dbde09d8
Author: Ian Lake <ilake@google.com>
Date: Fri Mar 18 22:16:45 2022
Remove dependency on ViewModels in enableSavedStateHandles()
Rather than requiring the creation of a ViewModel as part of
the call to enableSavedStateHandle(), defer that creation
until createSavedStateHandle() is actually called. This
ensures that enableSavedStateHandles() is safe to call before
the owner is attached to a Context, etc.
Relnote: "You can now retrieve a previously registered
`SavedStateProvider` from a `SavedStateRegistry` via
`getSavedStateProvider()`."
Test: updated tests
BUG: 215406268
Change-Id: I7ea470c1af0385b8bc9d8ca653c84cc8d224e6cf
M savedstate/savedstate/api/restricted_current.txt
M savedstate/savedstate/src/main/java/androidx/savedstate/SavedStateRegistry.java
M savedstate/savedstate/api/current.txt
M lifecycle/lifecycle-viewmodel-savedstate/build.gradle
M lifecycle/lifecycle-viewmodel-savedstate/src/main/java/androidx/lifecycle/SavedStateHandleSupport.kt
M lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/SavedStateHandleSupportTest.kt
M savedstate/savedstate/api/public_plus_experimental_current.txt
il...@google.com <il...@google.com> #4
This decoupling has been complete and will be available in Lifecycle 2.5.0-alpha06.
Description
Component used: Lifecycle
Version used: 2.5.0-alpha01
Currently the call to
enableSavedStateHandles()
creates aViewModel
using theViewModelStore
. This requires that the ViewModelStore be set on any component attempting to make the call, but there are scenarios where the call toenableSavedStateHandles
needs to happen before that in particular in the Fragment and Navigation components where the call is not immediately made when the object is constructed or sometimes not at all.If we remove the reliance on
SavedStateHandles
(and therefore view models), we can lean into theSavedStateProvider
APIs and the call toenableSavedStateHandles()
can be made before theViewModelStore
is set.