SaveStageRegistry is androidx savedstate: savedstate repository for developer tools, androidx FragmentActivity and fragments are adaptation of the tool.
role
Developers can easily sense the timing of state saving (staging) and its data recovery in the context of the conditions.
usage
- To obtain
SaveStageRegistry
Object instance, which can be passedSavedStateRegistryOwner.get
orComponentActivity.getSavedStateRegistry
- Through instance object injection (
registerSavedStateProvider
) own Provider (SavedStateProvider
). This Provider will be triggered before the component is reworked. The Bundle returned by the developer is mapped to the key provided at registration time and placed in the component’s total cache - In the corresponding life cycle, e.g
LifecycleObserver.onStateChanged
Invokes when triggeredconsumeRestoredStateForKey
Take out the Bundle you buried and make your own purchases - You can also call
runOnNextRecreation
Inject a class that implementsAutoRecreated
The Consume interface indicates that it will be triggered in the next rewrite, and can be used to obtain the relevant Bundle data when the consume interface is called back
aboutSavedStateRegistryOwner.get
The Jetpack Compose implementation, will be called ComponentActivity. SetOwners extension methods, will be injected SavedStateRegistryOwner. The injected object is a DecorView by calling its setTag with r.i.D.view_tree_saved_state_registry_OWNER as the key. When you get, you layer back through the View (via view.getparent ()), so don’t worry if you’ve called the setOwners method, you’ll always get it. For now, only Jetpack Compose is called in the source code. Otherwise, the developer needs to call it by itself if necessary.
Principle of Recreation
- Components in AndroidX, which already have one embedded inside
SavedStateRegistryController
Object that is called during the staging and recovery cycle of the native component - When it resumes, a lifecycle Observer is injected, namely
Recreator
- while
Reacrator
Will be inonStateChanged
When the reflection builder passes throughrunOnNextRecreation
Injected class, and triggered itonRecreated
methods