问题
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:
- Enable `Don't keep activities'
- Launch your app
- Tap the home button
- Your app will be killed immediately (
Activity.onDestroy
called)
来源:https://stackoverflow.com/questions/60232000/android-viewmodel-savedstatehandle