public abstract class Worker
extends ListenableWorker


A class that performs work synchronously on a background thread provided by WorkManager.

Worker classes are instantiated at runtime by WorkManager and the doWork() method is called on a pre-specified background thread (see Configuration.getExecutor()). This method is for synchronous processing of your work, meaning that once you return from that method, the Worker is considered to be finished and will be destroyed. If you need to do your work asynchronously or call asynchronous APIs, you should use ListenableWorker.

In case the work is preempted for any reason, the same instance of Worker is not reused. This means that doWork() is called exactly once per Worker instance. A new Worker is created if a unit of work needs to be rerun.

A Worker is given a maximum of ten minutes to finish its execution and return a ListenableWorker.Result. After this time has expired, the Worker will be signalled to stop.


Public constructors

Worker(Context context, WorkerParameters workerParams)

Public methods

abstract ListenableWorker.Result doWork()

Override this method to do your actual background processing.

ForegroundInfo getForegroundInfo()

Return an instance of ForegroundInfo if the WorkRequest is important to the user.

ListenableFuture<ForegroundInfo> getForegroundInfoAsync()

Return an instance of ForegroundInfo if the WorkRequest is important to the user.

final ListenableFuture<ListenableWorker.Result> startWork()

Override this method to start your actual background processing.

Inherited methods

Public constructors


public Worker (Context context, 
                WorkerParameters workerParams)