Stay organized with collections Save and categorize content based on your preferences.

ViewTreeLifecycleOwner

public final class ViewTreeLifecycleOwner


Summary

Public methods

static final LifecycleOwner

Retrieve the LifecycleOwner responsible for managing the given View.

static final void
ViewTreeLifecycleOwner.set(
    @NonNull View receiver,
    LifecycleOwner lifecycleOwner
)

Set the LifecycleOwner responsible for managing the given View.

Public methods

ViewTreeLifecycleOwner.get

public static final LifecycleOwner ViewTreeLifecycleOwner.get(@NonNull View receiver)

Retrieve the LifecycleOwner responsible for managing the given View. This may be used to scope work or heavyweight resources associated with the view that may span cycles of the view becoming detached and reattached from a window.

Returns
LifecycleOwner

The LifecycleOwner responsible for managing this view and/or some subset of its ancestors

ViewTreeLifecycleOwner.set

public static final void ViewTreeLifecycleOwner.set(
    @NonNull View receiver,
    LifecycleOwner lifecycleOwner
)

Set the LifecycleOwner responsible for managing the given View. Calls to get from this view or descendants will return lifecycleOwner.

This should only be called by constructs such as activities or fragments that manage a view tree and reflect their own lifecycle through a LifecycleOwner. Callers should only set a LifecycleOwner that will be stable. The associated lifecycle should report that it is destroyed if the view tree is removed and is not guaranteed to later become reattached to a window.

Parameters
LifecycleOwner lifecycleOwner

LifecycleOwner representing the manager of the given view