Those of you using sealed classes to wrap state, how are you persisting them? (e.g. onSaveInstanceState/onRestoreInstanceState) @alostpacket
g
ghedeon
02/05/2019, 11:13 PM
imho, ViewModel is supposed to keep it between configuration changes and stuff. For longer periods I'd consider pushing the state down to Repository.. Can't think of a proper
Keeping that in ViewModel. Then activity displays different things depending on which ViewState
However when user backgrounds app, Activity+ViewModel are getting killed
tenprint
02/05/2019, 11:57 PM
And ViewState comes back null when activity is restored
g
ghedeon
02/06/2019, 12:57 AM
a few things here. Activity is not necessarily killed when the app is in the background. Most of the times, if user comes back soon, the viewmodel should still have the value.
Second, if the activity and viewmodel is actually killed, then coming back shouldn't be different from the fresh start. Basically, just reload your data, like it's a first start of the activity. It's a totally normal flow and later you can think of possible measures to reduce delays, like disk/memory cache, etc.
t
tapchicoma
02/06/2019, 9:45 AM
your state can implement
Parcelable
with
@Parcelize
kotlin android extension, so it is easy to save/restore using
Bundle
in
onSaveInstanceState()
t
tenprint
02/06/2019, 3:40 PM
@tapchicoma That feature is experimental. Are people using it safely in production?