Class 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
- BackgroundWork
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidCancels a previously scheduled processing task.static booleanReturns true if the current platform supports deferrable background processing.static voidscheduleProcessing(String id, Date earliestBeginDate, boolean requiresNetwork, boolean requiresPower, Runnable task) Schedules a processing task.
-
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
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
-