public static final class WorkRequest.Builder

  1. Object
  2. WorkRequest.Builder
Builder for WorkRequest.

Methods

public WorkRequest.Builder setRequiresNetwork(boolean b)Requires any network connection.
public WorkRequest.Builder setRequiresUnmeteredNetwork(boolean b)Requires an unmetered network connection.
public WorkRequest.Builder setRequiresCharging(boolean b)Requires the device to be charging.
public WorkRequest.Builder setRequiresIdle(boolean b)Requires the device to be idle (Android only).
public WorkRequest.Builder setRequiresBatteryNotLow(boolean b)Requires the battery to not be low (Android only).
public WorkRequest.Builder setPeriodic(long minIntervalMillis)Makes the work periodic with the given minimum interval.
public WorkRequest.Builder setInitialDelay(long millis)Sets an initial delay before the first execution.
public WorkRequest.Builder putInputData(String key, String value)Adds a key-value pair to the input data passed to the worker.
public WorkRequest build()Builds the immutable work request.

Inherited methods

Method details

setRequiresNetwork

public WorkRequest.Builder setRequiresNetwork(boolean b)
Requires any network connection.

Parameters

b boolean
true to require a network

Returns

this builder for chaining

setRequiresUnmeteredNetwork

public WorkRequest.Builder setRequiresUnmeteredNetwork(boolean b)
Requires an unmetered network connection.

Parameters

b boolean
true to require an unmetered network

Returns

this builder for chaining

setRequiresCharging

public WorkRequest.Builder setRequiresCharging(boolean b)
Requires the device to be charging.

Parameters

b boolean
true to require charging

Returns

this builder for chaining

setRequiresIdle

public WorkRequest.Builder setRequiresIdle(boolean b)
Requires the device to be idle (Android only).

Parameters

b boolean
true to require device idle

Returns

this builder for chaining

setRequiresBatteryNotLow

public WorkRequest.Builder setRequiresBatteryNotLow(boolean b)
Requires the battery to not be low (Android only).

Parameters

b boolean
true to require battery-not-low

Returns

this builder for chaining

setPeriodic

public WorkRequest.Builder setPeriodic(long minIntervalMillis)
Makes the work periodic with the given minimum interval. Note that platforms enforce a minimum period (for example 15 minutes on Android) and iOS only approximates periodic work by resubmission.

Parameters

minIntervalMillis long
the minimum interval between executions in milliseconds

Returns

this builder for chaining

setInitialDelay

public WorkRequest.Builder setInitialDelay(long millis)
Sets an initial delay before the first execution.

Parameters

millis long
the delay in milliseconds

Returns

this builder for chaining

putInputData

public WorkRequest.Builder putInputData(String key, String value)
Adds a key-value pair to the input data passed to the worker.

Parameters

key String
the key
value String
the value

Returns

this builder for chaining

build

public WorkRequest build()
Builds the immutable work request.

Returns

the work request