# 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 />

```
public final class BackEventCompat
```

<br />

*** ** * ** ***

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

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#EDGE_LEFT() = 0` Indicates that the edge swipe starts from the left edge of the screen |
| `static final int` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#EDGE_NONE() = 2` Indicates that the back event was not triggered by an edge swipe back gesture. |
| `static final int` | `https://developer.android.com/reference/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/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/activity/BackEventCompat#BackEventCompat(android.window.BackEvent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/window/BackEvent.html backEvent)` Constructs a `https://developer.android.com/reference/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/android/window/BackEvent.html` object. |
| `https://developer.android.com/reference/androidx/activity/BackEventCompat#BackEventCompat(androidx.navigationevent.NavigationEvent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/NavigationEvent navigationEvent)` Constructs a `https://developer.android.com/reference/androidx/activity/BackEventCompat` from a `https://developer.android.com/reference/androidx/navigationevent/NavigationEvent` object. |
| `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting https://developer.android.com/reference/androidx/activity/BackEventCompat#BackEventCompat(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Long)( float touchX, float touchY, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float progress, int swipeEdge, long frameTimeMillis )` |

| ### Public methods |
|---|---|
| `final long` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#getFrameTimeMillis()()` Frame time of the back event. |
| `final float` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#getProgress()()` Value between 0 and 1 on how far along the back gesture is. |
| `final int` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#getSwipeEdge()()` Indicates which edge the swipe starts from. |
| `final float` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#getTouchX()()` Absolute X location of the touch point of this event in the coordinate space of the view that |
| `final float` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#getTouchY()()` Absolute Y location of the touch point of this event in the coordinate space of the view that received this back event. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/window/BackEvent.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 34) https://developer.android.com/reference/androidx/activity/BackEventCompat#toBackEvent()()` Convert this `https://developer.android.com/reference/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/android/window/BackEvent.html` object. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/NavigationEvent` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#toNavigationEvent()()` Convert this `https://developer.android.com/reference/androidx/activity/BackEventCompat` object to a `https://developer.android.com/reference/androidx/navigationevent/NavigationEvent` object. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/activity/BackEventCompat#toString()()` |

## Constants

### EDGE_LEFT

```
public static final int EDGE_LEFT = 0
```

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

### EDGE_NONE

```
public static final int EDGE_NONE = 2
```

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

```
public static final int EDGE_RIGHT = 1
```

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)
public BackEventCompat(@NonNull BackEvent backEvent)
```

Constructs a `https://developer.android.com/reference/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/androidx/activity/BackEventCompat`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/window/BackEvent.html backEvent` | 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)

```
public BackEventCompat(@NonNull NavigationEvent navigationEvent)
```

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

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

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

### BackEventCompat

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

```
@VisibleForTesting
public BackEventCompat(
    float touchX,
    float touchY,
    @FloatRange(from = 0.0, to = 1.0) float progress,
    int swipeEdge,
    long frameTimeMillis
)
```

## Public methods

### getFrameTimeMillis

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

```
public final long getFrameTimeMillis()
```

Frame time of the back event.

### getProgress

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

```
public final float getProgress()
```

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

### getSwipeEdge

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

```
public final int getSwipeEdge()
```

Indicates which edge the swipe starts from.

### getTouchX

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

```
public final float getTouchX()
```

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

- received this back event.

### getTouchY

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

```
public final float getTouchY()
```

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

### toBackEvent

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

```
@RequiresApi(value = 34)
public final @NonNull BackEvent toBackEvent()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull 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/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)

```
public final @NonNull NavigationEvent toNavigationEvent()
```

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

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

### toString

```
public @NonNull String toString()
```