1e41f4b71Sopenharmony_ci<!--RP1--> 2e41f4b71Sopenharmony_ci# Background Task Overview<!--RP1End--> 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Introduction 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciWhen you return to the home screen, lock the screen, or switch to another application, the current application is switched to the background. If the application continues all the activities when running in the background, the power consumption of the device may be high and the UI may freeze. To reduce the power consumption and deliver a positive user experience, the system manages the application running in the background. For example, the system can suspend the application process by stopping allocating CPU resources. It can also stop distributing [common events](../basic-services/common-event/common-event-overview.md) to the application process or terminate the process. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci- After an application is switched to the background for a short period of time (defined by the system), the system suspends the application process. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci- After an application running in the background is accessed for a short period of time (defined by the system), the system suspends the application process. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci- In case of resource insufficiency, the system terminates some application processes (by reclaiming all resources of these processes). 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciTo ensure the normal use of features such as music playback and calendar reminders in the background, the system provides constrained background tasks to extend the running time of applications in the background. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## Resource Usage Constraints 18e41f4b71Sopenharmony_ciThe system provides resource quotas for running processes, including the memory usage and CPU usage in a continuous period of time, as well as disk write I/O volume in 24 hours. When the quota is reached, the system generates a warning-level log if the process is running in the foreground, and terminates the process if it is running in the background. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Background Task Types 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciFor standard-system devices, the following types of constrained background tasks are provided: transient tasks, continuous tasks, deferred tasks, agent-powered reminders, and efficiency resources. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciYou can select a proper background task type to ensure that your application can continue running after switching to the background. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci- **Transient tasks**: suitable for tasks that have high requirements on real-time performance and can be completed in a short period of time, for example, status saving. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci- **Continuous tasks**: suitable for tasks that need to run in the background for a long time and can be perceived by users, such as music playback in the background, navigation, and device connection. Using continuous tasks to prevent application processes from being suspended. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci- **Deferred tasks**: suitable for tasks that do not have high requirements on real-time performance and can be executed at a later time. The system enqueues these tasks and schedules them in a unified manner based on the memory and power consumption. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci- **Agent-powered reminders**: After an application is switched to the background or an application process is terminated, the system sends a reminder on behalf of the application. You can create scheduled reminders for countdown timers, calendar events, and alarm clocks. 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci<!--Del--> 35e41f4b71Sopenharmony_ciFor system applications that provide basic capabilities, the system provides an API for [requesting energy resources](efficiency-resource-request.md). After an application calls the API, the system exempts the application from management.<!--DelEnd--> 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Figure 1** Selecting a type of background task 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci> **NOTE** 43e41f4b71Sopenharmony_ci> 44e41f4b71Sopenharmony_ci> - The system supports only constrained background tasks. If an application does not use a constrained background task or selects an inappropriate type of background task after switching to the background, its process will be suspended or terminated. 45e41f4b71Sopenharmony_ci> 46e41f4b71Sopenharmony_ci> - For an application that requests a constrained background task, only the priority of reclaiming the application process is increased. If system resources are severely insufficient, the application process may still be terminated. 47