Skip to content

//workflow/com.squareup.workflow1.ui.androidx/WorkflowLifecycleOwner/Companion/installOn

installOn

[androidJvm]
Content
fun installOn(view: View, findParentLifecycle: (View) -> Lifecycle? = { v -> findParentViewTreeLifecycle(v) })
More info

Creates a new WorkflowLifecycleOwner and sets it on view‘s tags so it can be later retrieved with get.

It’s very important that, once this function is called with a given view, that EITHER:

  1. The view gets attached at least once to ensure that the lifecycle eventually gets destroyed (because its parent is destroyed), or
  2. Someone eventually calls [destroyOnDetach](../destroy-on-detach.md), which will either schedule the lifecycle to destroyed if the view is attached, or destroy it immediately if it's detached.

If this is not done, any observers registered with the Lifecycle may be leaked as they will never see the destroy event.

Parameters

androidJvm

findParentLifecycle

A function that is called whenever view is attached, and should return the Lifecycle to use as the parent lifecycle. If not specified, defaults to looking up the view tree by calling ViewTreeLifecycleOwner.get on view‘s parent, and if none is found, then looking up view‘s context wrapper chain for something that implements LifecycleOwner. This only needs to be passed if view will be used as the root of a new view hierarchy, e.g. for a new dialog. If no parent lifecycle is found, then the lifecycle will become RESUMED when it’s attached for the first time, and stay in that state until it is re-attached with a non-null parent or destroyOnDetach is called.