Skip to content

//workflow/com.squareup.workflow1.ui.androidx/WorkflowSavedStateRegistryAggregator

WorkflowSavedStateRegistryAggregator

[androidJvm] @WorkflowUiExperimentalApi()

class WorkflowSavedStateRegistryAggregator

Manages a group of ViewTreeSavedStateRegistryOwners that are all saved to and restored from a single “parent” SavedStateRegistryOwner. SavedStateRegistryOwner is the new androidx alternative to the View.onSaveInstanceState system, and is required by Compose UI.

This class is designed to support a navigation container view that owns a a set of navigation “frames”, where a frame is something that can be navigated to/from. A frame loosely consists of a root View and its ViewTreeSavedStateRegistryOwner. For example:

  • a back stack container view will own an instance of [WorkflowSavedStateRegistryAggregator](index.md), and use it to assign a [ViewTreeSavedStateRegistryOwner](https://developer.android.com/reference/kotlin/androidx/savedstate/ViewTreeSavedStateRegistryOwner.html) for its top view.
  • a container view managing a set of windows will own an instance of [WorkflowSavedStateRegistryAggregator](index.md), and use it to assign a [ViewTreeSavedStateRegistryOwner](https://developer.android.com/reference/kotlin/androidx/savedstate/ViewTreeSavedStateRegistryOwner.html) to each dialog's content view.

Note that a ViewTreeSavedStateRegistryOwner works in parallel to a ViewTreeLifecycleOwner. Use WorkflowLifecycleOwner to ensure one is properly installed.

attachToParentRegistry must be called when the container view is attached to a window, and passed the parent registry. detachFromParentRegistry must be called when the container view is detached.

Call installChildRegistryOwnerOn to put a ViewTreeSavedStateRegistryOwner in place on each managed child view, before it is attached to a window. After that:

  • call [saveAndPruneChildRegistryOwner](save-and-prune-child-registry-owner.md) if the child is removed from service but may be restored before [detachFromParentRegistry](detach-from-parent-registry.md) is called (as when a back stack pushes and pops)
  • call [pruneAllChildRegistryOwnersExcept](prune-all-child-registry-owners-except.md) when views are permanently removed from service, taking care to identify the set that remain active

Note that this class does not offer support for the pre-Jetpack View.onSaveInstanceState mechanism. Container views must handle that themselves.

Constructors

WorkflowSavedStateRegistryAggregator [androidJvm] fun WorkflowSavedStateRegistryAggregator()

Functions

Name Summary
attachToParentRegistry [androidJvm]
Content
fun attachToParentRegistry(key: String, parentOwner: SavedStateRegistryOwner)
More info
Must be called when the owning container view gets attached to the window.


detachFromParentRegistry [androidJvm]
Content
fun detachFromParentRegistry()
More info
Must be called when the owning view detaches from the window.


installChildRegistryOwnerOn [androidJvm]
Content
fun installChildRegistryOwnerOn(view: View, key: String)
More info
Puts a new ViewTreeSavedStateRegistryOwner in place on view, registered with its ViewTreeLifecycleOwner.


pruneAllChildRegistryOwnersExcept [androidJvm]
Content
fun pruneAllChildRegistryOwnersExcept(keysToKeep: Collection<String> = emptyList())
More info
Drops all child ViewTreeSavedStateRegistryOwners and their restored state, except those identified in keysToKeep.


saveAndPruneChildRegistryOwner [androidJvm]
Content
fun saveAndPruneChildRegistryOwner(key: String)
More info
Call this when the View previously registered with key is being dropped, but may be replaced with a new instance before the container is destroyed – think of pushing and popping in a back stack.