# 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
public interface ExecutionEventListener
```

<br />

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

|---|---|
| `https://developer.android.com/reference/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 methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/work/ExecutionEventListener#onException(kotlin.Throwable,androidx.work.WorkInfo)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html throwable, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo)` Called when the work request fails from an exception after it has started. |
| `abstract void` | `https://developer.android.com/reference/androidx/work/ExecutionEventListener#onFinished(androidx.work.ListenableWorker.Result,androidx.work.WorkInfo)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ListenableWorker.Result result, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo )` Called when the worker finishes and returns a value. |
| `abstract void` | `https://developer.android.com/reference/androidx/work/ExecutionEventListener#onStarted(androidx.work.WorkInfo)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo)` Called when a work request starts executing i.e. `https://developer.android.com/reference/androidx/work/ListenableWorker#startWork()`. |
| `abstract void` | `https://developer.android.com/reference/androidx/work/ExecutionEventListener#onStopped(kotlin.Int,androidx.work.WorkInfo)(int stopReason, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo)` Called when a work request is stopped by the system after it has started. |

## Public methods

### onException

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

```
abstract void onException(@NonNull Throwable throwable, @NonNull WorkInfo workInfo)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html throwable` | Throwable thrown by worker |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo` | Snapshot of the work info |

### onFinished

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

```
abstract void onFinished(
    @NonNull ListenableWorker.Result result,
    @NonNull WorkInfo workInfo
)
```

Called when the worker finishes and returns a value.

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

### onStarted

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

```
abstract void onStarted(@NonNull WorkInfo workInfo)
```

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

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

### onStopped

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

```
abstract void onStopped(int stopReason, @NonNull WorkInfo workInfo)
```

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

| Parameters |
|---|---|
| `int stopReason` | 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 /> |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo workInfo` | Snapshot of the work info |