# ViewTreeOnBackPressedDispatcherOwner

Added in 1.5.0

*** ** * ** ***


```
public final class ViewTreeOnBackPressedDispatcherOwner
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` | `https://developer.android.com/reference/androidx/activity/ViewTreeOnBackPressedDispatcherOwner#(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/activity/OnBackPressedDispatcherOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. |
| `static final void` | `https://developer.android.com/reference/androidx/activity/ViewTreeOnBackPressedDispatcherOwner#(android.view.View).set(androidx.activity.OnBackPressedDispatcherOwner)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner onBackPressedDispatcherOwner )` Set the `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. |

## Public methods

### get

Artifact: [androidx.activity:activity](https://developer.android.com/jetpack/androidx/releases/activity) [View Source](https://cs.android.com/search?q=file:androidx/activity/ViewTreeOnBackPressedDispatcherOwner.kt+function:findViewTreeOnBackPressedDispatcherOwner) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/activity#1.5.0)

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

Retrieve the `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. This may be used to add a callback for the system back button.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` | The `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` associated with this view and/or some subset of its ancestors |

### set

Artifact: [androidx.activity:activity](https://developer.android.com/jetpack/androidx/releases/activity) [View Source](https://cs.android.com/search?q=file:androidx/activity/ViewTreeOnBackPressedDispatcherOwner.kt+function:setViewTreeOnBackPressedDispatcherOwner) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/activity#1.5.0)

```
public static final void set(
    @NonNull View receiver,
    @NonNull OnBackPressedDispatcherOwner onBackPressedDispatcherOwner
)
```

Set the `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` associated with the given `https://developer.android.com/reference/android/view/View.html`. Calls to `https://developer.android.com/reference/androidx/activity/package-summary#(android.view.View).findViewTreeOnBackPressedDispatcherOwner()` from this view or descendants will return `https://developer.android.com/reference/androidx/activity/package-summary#(android.view.View).setViewTreeOnBackPressedDispatcherOwner(androidx.activity.OnBackPressedDispatcherOwner)`.

This should only be called by constructs such as activities or dialogs that manage a view tree and handle the dispatch of the system back button. Callers should only set a `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` that will be *stable.*

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner onBackPressedDispatcherOwner` | `https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcherOwner` associated with the `https://developer.android.com/reference/android/view/View.html` |