ViewModel

What is the ViewModel

  • A data store component with host lifecycle awareness

  • The ViewModel holds data that persists after the page is destroyed and rebuilt due to configuration changes

    Configuration changes: horizontal and vertical screen switch, resolution adjustment, permission change, system font style change

The use of the ViewModel

Changed the implementation principle of ViewModel reuse

ViewModel data reuse advanced SaveState

  • SavedStatedHandle Data storage and recovery. Even if the ViewModel is not the same instance, the data it stores can be reused
  • SavedStateRegistryController: used to create SaveStatedRegistry
  • SavedStatedRegistry Data storage and recovery center.
  • SavedStateHandle: Single ViewModel data storage and recovery.