public final class BackgroundTask

  1. Object
  2. BackgroundTask

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.

Methods

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

Inherited methods

Method details

scheduleProcessing

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

Parameters

id String
a stable unique id for the task; it must be declared in the build hint listing permitted background task identifiers on iOS
earliestBeginDate Date
the earliest date at which the task may run, or null for as soon as convenient
requiresNetwork boolean
true if the task needs network connectivity
requiresPower boolean
true if the task needs the device to be charging
task Runnable
the work to run

cancel

public static void cancel(String id)
Cancels a previously scheduled processing task.

Parameters

id String
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