Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 88b56f69fc09de962a75a93a56fd7b60f643b452
Author: Ian Lake <ilake@google.com>
Date: Tue Apr 28 12:13:40 2020
Add support for lazy serialization in SavedStateHandle
Add a setSavedStateProvider() API to
SavedStateHandle that allows developers to build
their saved state just in time.
Test: new SavedStateHandleProviderTest
BUG: 155106862
Change-Id: Idd3cf6587613fda4e0fc22e3fd5f16afd77d7993
M lifecycle/lifecycle-viewmodel-savedstate/api/2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/current.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/public_plus_experimental_2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/restricted_2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/restricted_current.txt
A lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/SavedStateHandleProviderTest.kt
M lifecycle/lifecycle-viewmodel-savedstate/src/main/java/androidx/lifecycle/SavedStateHandle.java
https://android-review.googlesource.com/1295522
Branch: androidx-master-dev
commit 88b56f69fc09de962a75a93a56fd7b60f643b452
Author: Ian Lake <ilake@google.com>
Date: Tue Apr 28 12:13:40 2020
Add support for lazy serialization in SavedStateHandle
Add a setSavedStateProvider() API to
SavedStateHandle that allows developers to build
their saved state just in time.
Test: new SavedStateHandleProviderTest
BUG: 155106862
Change-Id: Idd3cf6587613fda4e0fc22e3fd5f16afd77d7993
M lifecycle/lifecycle-viewmodel-savedstate/api/2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/current.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/public_plus_experimental_2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/restricted_2.3.0-alpha03.txt
M lifecycle/lifecycle-viewmodel-savedstate/api/restricted_current.txt
A lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/SavedStateHandleProviderTest.kt
M lifecycle/lifecycle-viewmodel-savedstate/src/main/java/androidx/lifecycle/SavedStateHandle.java
il...@google.com <il...@google.com> #3
This has been fixed internally and will be available in Lifecycle 2.3.0-alpha03.
Description
Component used: lifecycle-viewmodel-savedstate Version used: 2.3.0-alpha01
SavedStateHandle
is currently the only mechanism for accessing saved instance state from aViewModel
. However, it currently forces you to only use objects that can be put in a Bundle sinceset()
verifies the type of object immediately.It would be nice if
SavedStateHandle
could also support lazy serialization of objects - namely, having some equivalent to being able to register aonSaveInstanceState()
like callback.It seems like this is precisely what something like
SavedStateProvider
could fill. You couldregisterSavedStateProvider()
with aString key
and aSavedStateProvider
and theSavedStateHandle
would be responsible for callingsaveState()
on each provider to fill in theBundle
for that key.It would be the responsibility of the
ViewModel
for maintaining the non-bundable object outside ofSavedStateHandle
(i.e., having its ownMutableLiveData
) as well as in implementing theSavedStateProvider
.There'd need be some way to access the previously saved state - perhaps the underlying
get()
method would return aBundle?
indicating the previously saved state and/orregisterSavedStateProvider()
could return that sameBundle?
.