Before Architecture Components we were used to save the UI state by onSaveInstanceState() method
SaveInstanceState:
We need to override onSaveInstanceState(Bundle savedInstanceState) and store the application state values in the form of bundle
|
@Override savedInstanceState.putBoolean("mybool", true); } |
Saved instanceState could save only parceble data.
This have limit to staore small amount of parceble data
ViewModel
ViewModel instance is part of Applications process and hence it is able to handle configuration changes.
If process dies, ViewModel instance lost and all the saved state will also be lost.
It will work for large objects also.
Don't have any restritions to save the state.
You can read about Viewmodel here