Read the original article:🔍 Introduction to Background Tasks in HarmonyOS Next
🚩Introduction
In HarmonyOS, when an application moves to the background, the system will probably suspend it to conserve power and resources. However, there are many real-world scenarios where apps must continue working in the background, whether to play music, remind users of a scheduled task, or fetch data.
HarmonyOS Next’s Background Tasks Kit provides an organized way to handle such use cases. There are 4 types of background tasks. In this article, we’ll look into all of the following:
- ⌛ Transient Tasks — Short-lived background extensions after app exit.
- 🔄 Continuous Tasks — Real-time, long-running tasks that stay active in the background.
- 💤 Deferred Tasks — Non-urgent background jobs that run when the conditions are met.
- 🚨 Agent-powered Reminders — System-handled timed notifications even when the app is closed or killed.
🆚Comparison of Task Types by Background Execution
In this section, you can find a detailed comparison of the various background task types available in HarmonyOS Next. In this way, you can gain a better understanding of the different types of background tasks.
⌛ Transient Tasks
In cases, the app needs to run in the background a little more, it can request a transient task to extend suspend time in the background.
✅ Use Cases are:
- Saving draft or state on app exit
- Logging analytics events
- Small cleanups or uploads
When to request: Only when in the foreground or during the onBackground() callback
Limit: Max 3 requests per time segment
Daily Quota: 10 minutes/day.
Max quota per request: By default, 3 minutes on Low Battery, 1 minute per request.
🔄 Continuous Tasks
In cases the app needs to perform perceivable operations (like music playback or navigation), it can request a continuous task to prevent it from being suspended.
✅ Use Cases are:
- Audio recording
- Running navigation continuously
- Ongoing data transfers (upload/download)
- Playing music in the background
Ability Limit: Only UIAbility (Stage Model) or ServiceAbility (FA Model) can request continuous tasks.
One-at-a-Time: Each UIAbility can only have 1 active continuous task at a time.
System Checks: App must do what it claims (e.g., if claiming to play audio, it must do so)
Resource Load: If a task causes excessive CPU/memory usage for a long period, the system may cancel it.
💤 Deferred Tasks
In cases, the app needs to run non-urgent tasks in the background — like syncing emails or uploading logs — it can request a Deferred Task. Deferred tasks are scheduled by the system based on conditions like battery level, network availability, etc.
✅ Use Cases are:
- Syncing email when connected to Wi-Fi
- Uploading logs while charging
- Running cleanup or maintenance tasks
Max Tasks: Up to 10 deferred tasks per time segment
Execution Time: Each callback (e.g., onWorkStart()) can run for up to 2 minutes.
Limitations Based on App Usage: The system categorizes apps based on usage frequency and applies execution limits.
System Delay: Tasks may be delayed if memory, battery, or temperature is not optimal.
API Limitations: Certain APIs cannot be called inside WorkSchedulerExtensionAbility (like camera, audio, media, etc.).
Auto-Termination: If not stopped on time, the system kills the task process.
🚨Agent-Powered Reminders
In cases, apps may need to remind users of time-sensitive events, even when running in the background or closed, the app can request Agent-Powered Reminders that enable it to schedule reminders even when it is killed.
⚠️To use agent-powered reminders in your app, you need to email Huawei for permission; but only tool apps are eligible.
✅ Use Cases include:
- Flash sale alerts from e-commerce apps
- Upcoming calendar events
- Wake-up or medication alarms
- Periodic reminders for productivity or tools apps
Max Active Reminders: A third-party app can only have 30 valid reminders at a time.
Expiration: The Reminder only expires when the user taps close. Repeating reminders remain valid.
Redirection Limit: Clicking the notification can only redirect to the originating app.
Tool-only Access: Currently, only tool-type apps can use this feature after requesting permission.
Control Restriction: After system-level control, it’s recommended to use Calendar Kit unless permission is granted. In this section, you can find a detailed comparison of the various background task types available in HarmonyOS Next. This information will help you gain a better understanding of the different types of background tasks.
🏁Conclusion
HarmonyOS Next makes it easy to manage background tasks, each designed for specific needs. Whether your app needs to act quickly when it goes to the background, play music continuously, sync data at the right moment, or send reminders after the app is closed! By getting to know Transient Tasks, Continuous Tasks, Deferred Tasks, and Agent-powered Reminders, you can create amazing apps that are both efficient and kind to battery life🔋.
Transient Task (ArkTS)-Background Tasks Kit-Application Framework - HUAWEI Developers
Continuous Task (ArkTS)-Background Tasks Kit-Application Framework - HUAWEI Developers
Agent-powered Reminder (ArkTS)-Background Tasks Kit-Application Framework - HUAWEI Developers
Deferred Task (ArkTS)-Background Tasks Kit-Application Framework - HUAWEI Developers


Top comments (0)