# ViewTreeLifecycleOwner

Added in 2.3.0

*** ** * ** ***


```
public final class ViewTreeLifecycleOwner
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` | `https://developer.android.com/reference/androidx/lifecycle/ViewTreeLifecycleOwner#(android.view.View).get()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html receiver)` Retrieve the `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/lifecycle/ViewTreeLifecycleOwner#(android.view.View).set(androidx.lifecycle.LifecycleOwner)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html receiver, https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner)` Set the `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. |

## Public methods

### get

Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeLifecycleOwner.android.kt+function:findViewTreeLifecycleOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

```
public static final LifecycleOwner get(@NonNull View receiver)
```

Retrieve the `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. 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 |
|---|---|
| `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` | The `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` responsible for managing this view and/or some subset of its ancestors |

### set

Artifact: [androidx.lifecycle:lifecycle-runtime](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ViewTreeLifecycleOwner.android.kt+function:setViewTreeLifecycleOwner) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0)

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

Set the `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` responsible for managing the given `https://developer.android.com/reference/android/view/View.html`. Calls to `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModelProvider).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 `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner`. Callers should only set a `https://developer.android.com/reference/androidx/lifecycle/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 |
|---|---|
| `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner` | LifecycleOwner representing the manager of the given view |