This article is rather incomplete, because we’ve lost persistence across process death — a rather important part of the Activity contract: onSaveInstanceState
.
But it requires us to parcelize or serialize any object that is not originally supported by the
Bundle
class, making it not typesafe. We also need to do the saving and restoring of the value manually. Years of evolution led us to rely on side classes that do this for us
The solution with the static ViewModel or the AndroidViewModel will lose the state across low memory condition / process death. See how you can verify this yourself here, which is why saving state to Bundle is important.
I was somewhat hoping that if this article makes the distinction between data and state, it would end up using viewmodel-savedstate
, to actually still save the state across low memory condition, which while I think is an overengineered solution, at least it exists and tries to solve the problem they created with the addition of ViewModel.