# BackEventCompat

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

*** ** * ** ***

<br />

```
class BackEventCompat
```

<br />

*** ** * ** ***

Compat around the `https://developer.android.com/reference/android/window/BackEvent.html` class

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#EDGE_LEFT() = 0` Indicates that the edge swipe starts from the left edge of the screen |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#EDGE_NONE() = 2` Indicates that the back event was not triggered by an edge swipe back gesture. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#EDGE_RIGHT() = 1` Indicates that the edge swipe starts from the right edge of the screen |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#BackEventCompat(android.window.BackEvent)(backEvent: https://developer.android.com/reference/android/window/BackEvent.html)` Constructs a `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/android/window/BackEvent.html` object. |
| `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#BackEventCompat(androidx.navigationevent.NavigationEvent)(navigationEvent: https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent)` Constructs a `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` object. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#BackEventCompat(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Long)( touchX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, touchY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, progress: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, swipeEdge: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, frameTimeMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/android/window/BackEvent.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#toBackEvent()()` Convert this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/android/window/BackEvent.html` object. |
| `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#toNavigationEvent()()` Convert this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` object. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#toString()()` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#frameTimeMillis()` Frame time of the back event. |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#progress()` Value between 0 and 1 on how far along the back gesture is. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#swipeEdge()` Indicates which edge the swipe starts from. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#touchX()` Absolute X location of the touch point of this event in the coordinate space of the view that |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat#touchY()` Absolute Y location of the touch point of this event in the coordinate space of the view that received this back event. |

## Constants

### EDGE_LEFT

```
const val EDGE_LEFT = 0: Int
```

Indicates that the edge swipe starts from the left edge of the screen

### EDGE_NONE

```
const val EDGE_NONE = 2: Int
```

Indicates that the back event was not triggered by an edge swipe back gesture. This applies to cases like using the back button in 3-button navigation or pressing a hardware back button.

### EDGE_RIGHT

```
const val EDGE_RIGHT = 1: Int
```

Indicates that the edge swipe starts from the right edge of the screen

## Public constructors

### BackEventCompat

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
@RequiresApi(value = 34)
BackEventCompat(backEvent: BackEvent)
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/android/window/BackEvent.html` object.

This constructor is used for API level 34 and above, mapping the `https://developer.android.com/reference/android/window/BackEvent.html`'s properties to the corresponding values in `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat`.

| Parameters |
|---|---|
| `backEvent: https://developer.android.com/reference/android/window/BackEvent.html` | The `https://developer.android.com/reference/android/window/BackEvent.html` instance to convert. |

### BackEventCompat

Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/activity#1.12.0)

```
BackEventCompat(navigationEvent: NavigationEvent)
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` object.

This constructor is used for compatibility with `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` and maps its properties to the corresponding values in `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat`.

| Parameters |
|---|---|
| `navigationEvent: https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` | The `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` instance to convert. |

### BackEventCompat

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/activity#1.11.0)

```
@VisibleForTesting
BackEventCompat(
    touchX: Float,
    touchY: Float,
    progress: @FloatRange(from = 0.0, to = 1.0) Float,
    swipeEdge: Int,
    frameTimeMillis: Long = 0
)
```

## Public functions

### toBackEvent

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
@RequiresApi(value = 34)
fun toBackEvent(): BackEvent
```

Convert this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/android/window/BackEvent.html` object.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/window/BackEvent.html` | A new `https://developer.android.com/reference/android/window/BackEvent.html` object populated with this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` data. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | if this API is called on an API prior to 34. |

### toNavigationEvent

Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/activity#1.12.0)

```
fun toNavigationEvent(): NavigationEvent
```

Convert this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` object.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` | A new `https://developer.android.com/reference/kotlin/androidx/navigationevent/NavigationEvent` object populated with this `https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat` data. |

### toString

```
open fun toString(): String
```

## Public properties

### frameTimeMillis

Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/activity#1.11.0)

```
val frameTimeMillis: Long
```

Frame time of the back event.

### progress

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
val progress: @FloatRange(from = 0.0, to = 1.0) Float
```

Value between 0 and 1 on how far along the back gesture is.

### swipeEdge

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
val swipeEdge: Int
```

Indicates which edge the swipe starts from.

### touchX

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
val touchX: Float
```

Absolute X location of the touch point of this event in the coordinate space of the view that

- received this back event.

### touchY

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/activity#1.8.0)

```
val touchY: Float
```

Absolute Y location of the touch point of this event in the coordinate space of the view that received this back event.