Architecture SavedStateHandle — the ViewModel’s complement

Picture by Charisse Kenion on Unsplash

When Architecture Component was introduced in 2017, many applaud thinking Google has finally solve the onSaveInstanceState challenge one has, since ViewModel seemingly preserved the state. However, to the disappointment of many, apparently it only preserve the state onConfigurationChange.

I even considered it as a Half Baked Solution as below, though I am not entirely right.

Nonetheless, Google is aware of this expectation from many, and in 2019, they came up with something that complements ViewModel in preserving the state, named SavedStateHandle.

Note 1: at the point of writing, this library is still in Alpha-5 state i.e. implementation ‘androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-alpha05’

Note 2: In case you’re not familiar with Architecture Component, check out below

--

--