Worker

public abstract class Worker
extends Object

java.lang.Object
   ↳ androidx.work.Worker


The basic unit of work.

Summary

Nested classes

enum Worker.WorkerResult

 

Public constructors

Worker()

Public methods

abstract Worker.WorkerResult doWork()

Override this method to do your actual background processing.

final Context getApplicationContext()
final String getId()
final Data getInputData()
final Data getOutputData()
final String[] getTriggeredContentAuthorities()
final Uri[] getTriggeredContentUris()
final void setOutputData(Data outputData)

Call this method to pass an Data object to Worker that is dependent on this one.

Inherited methods

Public constructors

Worker

Worker ()

Public methods

doWork

Worker.WorkerResult doWork ()

Override this method to do your actual background processing.

Returns
Worker.WorkerResult The result of the work, corresponding to a Worker.WorkerResult value. If a different value is returned, the result shall be defaulted to Worker.WorkerResult.FAILURE.

getApplicationContext

Context getApplicationContext ()

Returns
Context

getId

String getId ()

Returns
String

getInputData

Data getInputData ()

Returns
Data

getOutputData

Data getOutputData ()

Returns
Data

getTriggeredContentAuthorities

String[] getTriggeredContentAuthorities ()

Returns
String[]

getTriggeredContentUris

Uri[] getTriggeredContentUris ()

Returns
Uri[]

setOutputData

void setOutputData (Data outputData)

Call this method to pass an Data object to Worker that is dependent on this one. Note that if there are multiple Workers that contribute to the target, the Data will be merged together, so it is up to the developer to make sure that keys are unique. New values and types will clobber old values and types, and if there are multiple parent Workers of a child Worker, the order of clobbering may not be deterministic. This method is invoked after doWork() returns Worker.WorkerResult.SUCCESS and there are chained jobs available. For example, if you had this structure: WorkManager.getInstance(context) .enqueueWithDefaults(WorkerA.class, WorkerB.class) .then(WorkerC.class) .enqueue() This method would be called for both WorkerA and WorkerB after their successful completion, modifying the input Data for WorkerC.

Parameters
outputData Data: An Data object that will be merged into the input Data of any OneTimeWorkRequest that is dependent on this one, or null if there is nothing to contribute