android_background_task_manager library
Android Background Task Manager
A Flutter package for managing background tasks on Android using WorkManager and AlarmManager. This package provides a unified API for scheduling and managing background tasks without needing to touch native Android code.
Features
- Easy Task Registration: Register task callbacks with unique IDs
- Flexible Scheduling: Schedule one-time or periodic tasks with various constraints
- Reliable Execution: Uses WorkManager for reliable background execution
- Local Persistence: Tracks task state across app restarts
- Error Handling: Comprehensive error handling with descriptive exceptions
- Testing Support: Built-in support for testing and debugging
Usage
import 'package:android_background_task_manager/android_background_task_manager.dart';
Classes
- AndroidBackgroundTaskManager
- Main manager class for Android background tasks.
- AndroidBackgroundTaskMethodChannel
- Method channel for communicating with native Android code.
- ScheduledTaskInfo
- Information about a scheduled task.
- TaskOptions
- Configuration options for scheduling background tasks.
- TaskPersistence
- Handles local persistence of scheduled task information.
Typedefs
-
BackgroundTaskCallback
= Future<
void> Function(String taskId, Map<String, dynamic> ? data) - Callback function type for background task execution.
Exceptions / Errors
- AndroidBackgroundTaskException
- Base exception class for all Android Background Task Manager errors.
- DuplicateTaskIdException
- Thrown when attempting to register a task with an ID that already exists.
- InvalidFrequencyException
- Thrown when the minimum frequency requirement for periodic tasks is not met.
- InvalidTaskOptionsException
- Thrown when task options contain invalid configuration values.
- NativeOperationException
- Thrown when a native Android operation fails.
- NotInitializedException
- Thrown when the Android Background Task Manager is not properly initialized.
- PersistenceException
- Thrown when there's an issue with local persistence.
- TaskNotRegisteredException
- Thrown when attempting to schedule a task that hasn't been registered yet.
- TaskSchedulingConflictException
- Thrown when there's a conflict in task scheduling.