Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Request for new functionality
View staffing
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?
.