ExecutionEventListener


@ExperimentalEventsApi
public 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 methods

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

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

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

Called when the worker finishes and returns a value.

abstract void

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

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

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

Public methods

onException

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

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

Parameters
@NonNull Throwable throwable

Throwable thrown by worker

@NonNull WorkInfo workInfo

Snapshot of the work info

onFinished

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

Called when the worker finishes and returns a value.

Parameters
@NonNull ListenableWorker.Result result

Result from work finishing

@NonNull WorkInfo workInfo

Snapshot of the work info

onStarted

abstract void onStarted(@NonNull WorkInfo workInfo)

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

Parameters
@NonNull WorkInfo workInfo

Snapshot of the work info

onStopped

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

@NonNull WorkInfo workInfo

Snapshot of the work info