Class WorkRequest
Describes a unit of constraint-aware background work to be scheduled with
BackgroundWork#schedule(WorkRequest). The constraints map to Android WorkManager
constraints and iOS BGTaskScheduler request options.
Input data is a string-keyed string map so that it can survive serialization into the platform scheduler and a subsequent cold launch of the app process.
Usage
WorkRequest req = WorkRequest.builder("sync", SyncWorker.class)
.setRequiresNetwork(true)
.setRequiresCharging(true)
.setPeriodic(6 * 60 * 60 * 1000L)
.putInputData("account", "primary")
.build();
BackgroundWork.schedule(req);
See also
-
BackgroundWork
-
BackgroundWorker
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic WorkRequest.Builderbuilder(String id, Class<? extends BackgroundWorker> worker) Creates a new work request builder.getId()Returns the unique work id.longReturns the initial delay before the first execution in milliseconds.Returns an immutable copy of the input data.longReturns the minimum interval between periodic executions in milliseconds, or 0 for one-shot work.Returns the fully qualified class name of theBackgroundWorkerthat performs the work.booleanReturns true if the work repeats periodically.booleanReturns true if the work requires the battery to not be low (Android only).booleanReturns true if the work requires the device to be charging.booleanReturns true if the work requires the device to be idle (Android only).booleanReturns true if the work requires any network connection.booleanReturns true if the work requires an unmetered (for example Wi-Fi) network.
-
Method Details
-
getId
Returns the unique work id.
Returns
the work id
-
getWorkerClass
Returns the fully qualified class name of the
BackgroundWorkerthat performs the work.Returns
the worker class name
-
isRequiresNetwork
public boolean isRequiresNetwork()Returns true if the work requires any network connection.
Returns
true if a network is required
-
isRequiresUnmeteredNetwork
public boolean isRequiresUnmeteredNetwork()Returns true if the work requires an unmetered (for example Wi-Fi) network.
Returns
true if an unmetered network is required
-
isRequiresCharging
public boolean isRequiresCharging()Returns true if the work requires the device to be charging.
Returns
true if charging is required
-
isRequiresIdle
public boolean isRequiresIdle()Returns true if the work requires the device to be idle (Android only).
Returns
true if device idle is required
-
isRequiresBatteryNotLow
public boolean isRequiresBatteryNotLow()Returns true if the work requires the battery to not be low (Android only).
Returns
true if battery-not-low is required
-
isPeriodic
public boolean isPeriodic()Returns true if the work repeats periodically.
Returns
true if periodic
-
getMinIntervalMillis
public long getMinIntervalMillis()Returns the minimum interval between periodic executions in milliseconds, or 0 for one-shot work.
Returns
the minimum periodic interval in milliseconds
-
getInitialDelayMillis
public long getInitialDelayMillis()Returns the initial delay before the first execution in milliseconds.
Returns
the initial delay in milliseconds
-
getInputData
-
builder
Creates a new work request builder.
Parameters
-
id: a stable unique id for the work; scheduling another request with the same id replaces it -
worker: the worker class that performs the work; it must have a public no-arg constructor
Returns
a new builder
-
-