Android viewModel savedStateHandle

落爺英雄遲暮 提交于 2021-01-27 21:09:27

问题


This is more of a conceptual question.

Android recently introduced the concept of handling the state during process death inside viewModel rather than savedInstanceState which previously used to be in Activity or Fragment.

My question is how do I test this process death? If I rightly understand the documentation, the Process death happens to be Android killing the app due to full memory when app is no longer used in background.

Also will the viewModel save the state when user kills the app from the RAM? So that I can retrieve the state as the user opens the app again.


回答1:


  1. Enable `Don't keep activities'
  2. Launch your app
  3. Tap the home button
  4. Your app will be killed immediately (Activity.onDestroy called)


来源:https://stackoverflow.com/questions/60232000/android-viewmodel-savedstatehandle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!