view-model-pattern

Does ViewModel survive Activity save and restore?

放肆的年华 提交于 2019-12-10 00:58:57
问题 Instances of the new ViewModel class can survive configuration changes if used in the following fashion: mViewModel = ViewModelProviders.of(this).get(MyViewModel.class); However, in addition to configuration changes, there is also a save-restore scenario when the entire application's process is being killed. Will fields' values inside ViewModel be preserved during save-restore scenario? Edit: based on the answer to this question, I wrote this article: Android ViewModel Architecture Component