Class WorkRequest

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

public final class WorkRequest extends 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

  • 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, 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