ExecutionEventListener


@ExperimentalEventsApi
interface ExecutionEventListener

Known direct subclasses
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 Unit
onException(throwable: Throwable, workInfo: WorkInfo)

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

suspend Unit

Called when the worker finishes and returns a value.

suspend Unit
onStarted(workInfo: WorkInfo)

Called when a work request starts executing i.e. ListenableWorker.startWork.

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

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

Public functions

onException

Added in 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: Throwable

Throwable thrown by worker

workInfo: WorkInfo

Snapshot of the work info

onFinished

Added in 2.12.0
suspend fun onFinished(result: ListenableWorker.Result, workInfo: WorkInfo): Unit

Called when the worker finishes and returns a value.

Parameters
result: ListenableWorker.Result

Result from work finishing

workInfo: WorkInfo

Snapshot of the work info

onStarted

Added in 2.12.0
suspend fun onStarted(workInfo: WorkInfo): Unit

Called when a work request starts executing i.e. ListenableWorker.startWork.

Parameters
workInfo: WorkInfo

Snapshot of the work info

onStopped

Added in 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: Int

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

workInfo: WorkInfo

Snapshot of the work info