# Class BackgroundTask

java.lang.Object
com.codename1.background.BackgroundTask

public final class BackgroundTask extends java.lang.Object

Schedules a one-shot deferrable processing task that the operating system runs at a convenient time after an earliest-begin date. On iOS this maps to a `BGProcessingTaskRequest`; on Android it maps to a one-shot WorkManager request with an initial delay; in the simulator it runs on a timer.

The `Runnable` passed here runs in the foreground simulator and during a live app session. On iOS, after the app process has been killed, the registered task identifier is relaunched by the OS and the work is reconstructed from the persisted schedule; for that cold-launch path prefer `BackgroundWork` with a `BackgroundWorker` class, which is reconstructed via its no-arg constructor.

##### See also

- BackgroundWork

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `cancel(String id)`
  Cancels a previously scheduled processing task.
  `static boolean`
  `isSupported()`
  Returns true if the current platform supports deferrable background processing.
  `static void`
  `scheduleProcessing(String id, Date earliestBeginDate, boolean requiresNetwork, boolean requiresPower, Runnable task)`
  Schedules a processing task.

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

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

- ## Method Details

  - ### scheduleProcessing

    public static void scheduleProcessing(String id, Date earliestBeginDate, boolean requiresNetwork, boolean requiresPower, Runnable task)

    Schedules a processing task.

    ###### Parameters

    - `id`: a stable unique id for the task; it must be declared in the build hint listing permitted background task identifiers on iOS

    - `earliestBeginDate`: the earliest date at which the task may run, or null for as soon as convenient

    - `requiresNetwork`: true if the task needs network connectivity

    - `requiresPower`: true if the task needs the device to be charging

    - `task`: the work to run

  - ### cancel

    public static void cancel(String id)

    Cancels a previously scheduled processing task.

    ###### Parameters

    - `id`: the task id

  - ### isSupported

    public static boolean isSupported()

    Returns true if the current platform supports deferrable background processing.

    ###### Returns

    true if background processing is supported