Android Architecture Components(Jetpack 的一部分)是一些库,用于帮助构建健壮、可维护的应用——包括 ViewModel(生命周期感知状态)、LiveData/StateFlow(可观察数据)和 Room(数据库抽象)。它们支持推荐的架构模式。
ViewModel — 生命周期感知的状态容器
VIEWMODEL holds UI-related state and logic, SURVIVING configuration changes:
→ state stored in a ViewModel SURVIVES screen rotation (the activity recreates, but the
ViewModel persists) → solves the lost-state-on-rotation problem
→ separates UI logic from the Activity/Fragment (the View just observes/displays)
