-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2019-12-06:ViewModel的出现是为了解决什么问题?并简要说说它的内部原理? #205
Comments
viewModel出现为了解决什么问题? |
存储UI数据 |
在Activity中有onRetainNonConfigurationInstance和getLastNonConfigurationInstance这两个方法,主要是借助于系统的机制,保存一些持续性的数据 ViewModel主要就是为了解决内存泄漏并且保存UI数据的问题,开发者应该只在ViewModel中保存与Context无关的UI数据 |
ViewModel 类:辅助程序类,用来保存应用UI数据,负责为界面准备数据。它会在配置变更后继续存在。将应用所有的UI数据保存在 ViewModel 中,而不是 Activity 中,这样就能确保数据不会受到配置变更的影响。 |
No description provided.
The text was updated successfully, but these errors were encountered: