stop static method
Stop the background-fetch API from firing events.
If provided with an optional taskId
, will halt only that task. If provided no taskId
, will stop all tasks.
BackgroundFetch.configure(BackgroundFetchConfig(
minimumFetchInterval: 15
), (String taskId) { // <-- Event callback
print("[BackgroundFetch] taskId: $taskId");
BackgroundFetch.finish(taskId);
}, (String taskId) async { // <-- Timeout callback
// This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId)
BackgroundFetch.finish(taskId);
});
BackgroundFetch.scheduleTask(TaskConfig({
taskId: 'foo',
delay: 10000,
forceAlarmManager: true
});
.
.
.
// Stop only the task named 'foo', leaving the primary background-fetch events running.
BackgroundFetch.stop('foo');
.
.
.
// Or stop ALL tasks
BackgroundFetch.stop();
Implementation
static Future<int> stop([String? taskId]) async {
int status = await _methodChannel.invokeMethod('stop', taskId);
return status;
}