
简介
该用户还未填写简介
擅长的技术栈
可提供的服务
暂无可提供的服务
ViewModel 在 Fragment 中不会因配置改变而销毁的原因其实是因为其声明的 ViewModel 是存储在 FragmentManagerViewModel 中的,而 FragmentManagerViewModel 是存储在宿主 Activity 中的 ViewModelStore 中,又因 Activity 中 ViewModelStore不会因配置改变而销毁,故 Fragment

根据官方文档给出的解释:宿主(LifecycleOwner):具有生命周期的组件,如 Activity、Fragment、Service 和 Application。观察者(LifecycleObserver):监听宿主生命周期状态变化的组件。生命周期状态(State):包括 、、、、 等,用于描述宿主的当前状态。生命周期事件(Event):如 、 等,由宿主状态变化触发。为什么使用lifecyc
ViewModel 在 Fragment 中不会因配置改变而销毁的原因其实是因为其声明的 ViewModel 是存储在 FragmentManagerViewModel 中的,而 FragmentManagerViewModel 是存储在宿主 Activity 中的 ViewModelStore 中,又因 Activity 中 ViewModelStore不会因配置改变而销毁,故 Fragment

ViewModel 在 Fragment 中不会因配置改变而销毁的原因其实是因为其声明的 ViewModel 是存储在 FragmentManagerViewModel 中的,而 FragmentManagerViewModel 是存储在宿主 Activity 中的 ViewModelStore 中,又因 Activity 中 ViewModelStore不会因配置改变而销毁,故 Fragment








