ScheduleResult enum
Result of scheduling a task.
Returned by NativeWorkManager.enqueue to indicate whether the OS accepted the task for scheduling.
Success Case
final result = await NativeWorkManager.enqueue(
taskId: 'sync-data',
trigger: TaskTrigger.oneTime(),
worker: NativeWorker.httpSync(url: 'https://api.example.com/sync'),
);
if (result == ScheduleResult.accepted) {
print('Task scheduled successfully');
}
Handling Rejection
final result = await NativeWorkManager.enqueue(
taskId: 'upload-large-file',
trigger: TaskTrigger.oneTime(),
worker: NativeWorker.httpUpload(
url: 'https://api.example.com/upload',
filePath: '/data/large-file.zip',
),
);
switch (result) {
case ScheduleResult.accepted:
showNotification('Upload scheduled');
break;
case ScheduleResult.rejectedOsPolicy:
showError('Device cannot schedule tasks (low battery?)');
break;
case ScheduleResult.throttled:
showWarning('Too many tasks - try again later');
break;
}
Why Tasks Get Rejected
rejectedOsPolicy:
- Device in power save mode
- Too many tasks already scheduled
- App in background restrictions (Android)
- Constraints too restrictive
throttled:
- Too many enqueue() calls in short period
- OS rate limiting to prevent abuse
- Typical limit: ~500 tasks per hour
Best Practices
✅ Do check the result and handle rejections gracefully ✅ Do implement retry logic with exponential backoff ✅ Do inform users if critical tasks can't be scheduled
❌ Don't assume tasks are always accepted ❌ Don't schedule hundreds of tasks rapidly ❌ Don't ignore throttling errors
See also: NativeWorkManager.enqueue
Values
- accepted → const ScheduleResult
-
Task was successfully scheduled.
The OS accepted the task and will execute it according to the trigger and constraints. This is the normal success case.
- rejectedOsPolicy → const ScheduleResult
-
Task was rejected due to OS policy.
Common causes:
- Device in power save mode
- Too many tasks already scheduled
- Background execution restrictions
- Constraints cannot be satisfied
- throttled → const ScheduleResult
-
Task was throttled (too many requests).
The app is scheduling tasks too rapidly. The OS rejected this task to prevent resource abuse. Wait and retry with exponential backoff.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
values
→ const List<
ScheduleResult> - A constant List of the values in this enum, in order of their declaration.