# Class WorkRequest

java.lang.Object
com.codename1.background.WorkRequest

public final class WorkRequest extends java.lang.Object

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
  Modifier and Type
  Class
  Description
  `static final class`
  `WorkRequest.Builder`
  Builder for `WorkRequest`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static WorkRequest.Builder`
  `builder(String id, java.lang.Class<? extends BackgroundWorker> worker)`
  Creates a new work request builder.
  `String`
  `getId()`
  Returns the unique work id.
  `long`
  `getInitialDelayMillis()`
  Returns the initial delay before the first execution in milliseconds.
  `Map<String,String>`
  `getInputData()`
  Returns an immutable copy of the input data.
  `long`
  `getMinIntervalMillis()`
  Returns the minimum interval between periodic executions in milliseconds, or 0 for one-shot work.
  `String`
  `getWorkerClass()`
  Returns the fully qualified class name of the `BackgroundWorker` that performs the work.
  `boolean`
  `isPeriodic()`
  Returns true if the work repeats periodically.
  `boolean`
  `isRequiresBatteryNotLow()`
  Returns true if the work requires the battery to not be low (Android only).
  `boolean`
  `isRequiresCharging()`
  Returns true if the work requires the device to be charging.
  `boolean`
  `isRequiresIdle()`
  Returns true if the work requires the device to be idle (Android only).
  `boolean`
  `isRequiresNetwork()`
  Returns true if the work requires any network connection.
  `boolean`
  `isRequiresUnmeteredNetwork()`
  Returns true if the work requires an unmetered (for example Wi-Fi) network.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### getId

    public String getId()

    Returns the unique work id.

    ###### Returns

    the work id

  - ### getWorkerClass

    public String getWorkerClass()

    Returns the fully qualified class name of the `BackgroundWorker` that 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

    public Map<String,String> getInputData()

    Returns an immutable copy of the input data.

    ###### Returns

    the input data, never null

  - ### builder

    public static WorkRequest.Builder builder(String id, java.lang.Class<? extends BackgroundWorker> worker)

    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