ViewStateCache

@WorkflowUiExperimentalApi
class ViewStateCache : Parcelable

Handles persistence chores for container views that manage a set of Named renderings, showing a view for one at a time -- think back stacks or tab sets.

This class implements Parcelable so that it can be preserved from a container view's own View.saveHierarchyState method. A simple container can return SavedState from that method rather than creating its own persistence class.

Container views using this class must call attachToParentRegistry and detachFromParentRegistry when they are attached and detached, respectively.

Constructors

ViewStateCache
Link copied to clipboard
fun ViewStateCache()

Types

CREATOR
Link copied to clipboard
object CREATOR : Parcelable.Creator<ViewStateCache>
SavedState
Link copied to clipboard
class SavedState : View.BaseSavedState

Convenience for use in View.onSaveInstanceState and View.onRestoreInstanceState methods of container views that have no other state of their own to save.

Functions

attachToParentRegistry
Link copied to clipboard
fun attachToParentRegistry(key: String, parentOwner: SavedStateRegistryOwner)

Must be called whenever the owning view is attached to a window. Must eventually be matched with a call to detachFromParentRegistry.

describeContents
Link copied to clipboard
open override fun describeContents(): Int
detachFromParentRegistry
Link copied to clipboard
fun detachFromParentRegistry()

Must be called whenever the owning view is detached from a window. Must be matched with a call to attachToParentRegistry.

prune
Link copied to clipboard
fun prune(retaining: Collection<Named<*>>)

To be called when the set of hidden views changes but the visible view remains the same. Any cached view state held for renderings that are not compatible those in retaining will be dropped.

restore
Link copied to clipboard
fun restore(from: ViewStateCache)

Replaces the state of the receiver with that of from. Typical usage is to call this from a container view's View.onRestoreInstanceState.

update
Link copied to clipboard
fun update(retainedRenderings: Collection<Named<*>>, oldViewMaybe: View?, newView: View)
writeToParcel
Link copied to clipboard
open override fun writeToParcel(parcel: Parcel, flags: Int)