Android viewModel savedStateHandle [英] Android viewModel savedStateHandle
问题描述
这更多是一个概念性的问题.
This is more of a conceptual question.
Android最近引入了在ViewModel内部处理进程死机时处理状态的概念,而不是以前曾在Activity或Fragment中使用的 savedInstanceState
.
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.
我的问题是如何测试此过程的死亡?如果我正确地理解了文档,那么当应用程序不再在后台使用时,进程死亡恰好是Android杀死了该应用程序,因为该应用程序的内存已满.
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.
当用户从RAM中杀死应用程序时,viewModel也将保存状态吗?这样我就可以在用户再次打开应用程序时检索状态.
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.
推荐答案
- 启用不保留活动"
- 启动您的应用
- 点击主页按钮
- 您的应用将立即被杀死(调用
Activity.onDestroy
)
这篇关于Android viewModel savedStateHandle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!