public interface BackgroundWorker

Implemented by an application class to perform constraint-aware background work scheduled through BackgroundWork#schedule(WorkRequest).

The implementing class MUST have a public no-argument constructor: the platform may reconstruct a fresh instance after the app process has been killed and cold launched to run the work, so no state from the foreground app is available. Pass any required state through the work request input data.

Methods

public abstract void performWork(String workId, Map<String, String> inputData, long deadline, Callback<Boolean> onComplete)Performs the background work.

Method details

performWork

public abstract void performWork(String workId, Map<String, String> inputData, long deadline, Callback<Boolean> onComplete)
Performs the background work. The implementation should call onComplete with Boolean.TRUE on success or Boolean.FALSE to request that the platform retry the work later. The work must finish before deadline; if it does not, the platform may terminate it.

Parameters

workId String
the id of the work request being executed
inputData Map<String, String>
the immutable input data supplied to the work request
deadline long
the time in milliseconds since the epoch by which the work must finish
onComplete Callback<Boolean>
callback invoked with the outcome (true for success, false to retry)