# ViewTreeViewModelStoreOwner

Added in 2.3.0

*** ** * ** ***


```
public final class ViewTreeViewModelStoreOwner
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` | `https://developer.android.com/reference/androidx/lifecycle/ViewTreeViewModelStoreOwner#(android.view.View).get()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html receiver)` Retrieves the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/lifecycle/ViewTreeViewModelStoreOwner#(android.view.View).set(androidx.lifecycle.ViewModelStoreOwner)(@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/ViewModelStoreOwner viewModelStoreOwner)` Sets the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. |

## Public methods

### get

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

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

Retrieves the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`.

Used to retain state associated with this view across configuration changes.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` | `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with this view or its ancestors |

### set

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

```
public static final void set(@NonNull View receiver, ViewModelStoreOwner viewModelStoreOwner)
```

Sets the `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`.

Calls to `https://developer.android.com/reference/androidx/lifecycle/package-summary#(android.view.View).findViewTreeViewModelStoreOwner()` from this view or its descendants will return `https://developer.android.com/reference/androidx/lifecycle/package-summary#(android.view.View).setViewTreeViewModelStoreOwner(androidx.lifecycle.ViewModelStoreOwner)`.

This should only be called by constructs such as `Activity`s or `Fragment`s that manage a view tree and retain state through a `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner`. Callers should only set a `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` that is stable. The associated `https://developer.android.com/reference/androidx/lifecycle/ViewModelStore` should be cleared 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/ViewModelStoreOwner viewModelStoreOwner` | `https://developer.android.com/reference/androidx/lifecycle/ViewModelStoreOwner` to associate with this `https://developer.android.com/reference/android/view/View.html` |