public final class BackgroundTask
- Object
- 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.
See also
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
idString- a stable unique id for the task; it must be declared in the build hint listing permitted background task identifiers on iOS
earliestBeginDateDate- the earliest date at which the task may run, or null for as soon as convenient
requiresNetworkboolean- true if the task needs network connectivity
requiresPowerboolean- true if the task needs the device to be charging
taskRunnable- the work to run
cancel
public static void cancel(String id)Cancels a previously scheduled processing task.
Parameters
idString- 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