# ExecutionEventListener

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/ExecutionEventListener.kt+class:androidx.work.ExecutionEventListener) Added in [2.12.0](https://developer.android.com/jetpack/androidx/releases/work#2.12.0)

*** ** * ** ***


```
@ExperimentalEventsApi
interface ExecutionEventListener
```

<br />

Known direct subclasses [WorkMetricsInfoRepository](https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfoRepository)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/analytics/WorkMetricsInfoRepository` | Repository class that calculates and stores metrics info and analytics about workers. |

*** ** * ** ***

Listener interface that is called for events related to a worker executing.

Note that a given work request may have multiple executions due to stops and retries.

## Summary

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/ExecutionEventListener#onException(kotlin.Throwable,androidx.work.WorkInfo)(throwable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html, workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo)` Called when the work request fails from an exception after it has started. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/ExecutionEventListener#onFinished(androidx.work.ListenableWorker.Result,androidx.work.WorkInfo)(result: https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result, workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo)` Called when the worker finishes and returns a value. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/ExecutionEventListener#onStarted(androidx.work.WorkInfo)(workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo)` Called when a work request starts executing i.e. `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/ExecutionEventListener#onStopped(kotlin.Int,androidx.work.WorkInfo)(stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo)` Called when a work request is stopped by the system after it has started. |

## Public functions

### onException

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

```
suspend fun onException(throwable: Throwable, workInfo: WorkInfo): Unit
```

Called when the work request fails from an exception after it has started.

| Parameters |
|---|---|
| `throwable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` | Throwable thrown by worker |
| `workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` | Snapshot of the work info |

### onFinished

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

```
suspend fun onFinished(result: ListenableWorker.Result, workInfo: WorkInfo): Unit
```

Called when the worker finishes and returns a value.

| Parameters |
|---|---|
| `result: https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result` | `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result` from work finishing |
| `workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` | Snapshot of the work info |

### onStarted

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

```
suspend fun onStarted(workInfo: WorkInfo): Unit
```

Called when a work request starts executing i.e. `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()`.

| Parameters |
|---|---|
| `workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` | Snapshot of the work info |

### onStopped

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

```
suspend fun onStopped(stopReason: Int, workInfo: WorkInfo): Unit
```

Called when a work request is stopped by the system after it has started.

| Parameters |
|---|---|
| `stopReason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Reason why work stopped Value is one of the following: - `-512` - `-256` - `-128` - `1` - `2` - `3` - `4` - `5` - `6` - `7` - `8` - `9` - `10` - `11` - `12` - `13` - `14` - `15` <br /> |
| `workInfo: https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` | Snapshot of the work info |