Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Huawei launches Hongmeng HarmonyOS background task management development guide, including specific usage scenarios and detailed development steps.

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >

Share

Shulou(Shulou.com)12/24 Report--

Thanks to CTOnews.com netizen Xiao Zhan for the clue delivery! CTOnews.com, November 28, in response to developers' questions about using background tasks, Huawei has launched a development guide for background tasks with clearer concepts and clearer logical structure, including specific usage scenarios and detailed development steps to help developers fully understand the necessity of applying for background tasks, types of background tasks and application procedures.

According to reports, operations such as the return of the device to the main interface, locking screen, and application switching will make the application fall back to the background. If the application continues to be active after it is retreated to the background, it may cause fast power consumption of the equipment, stuttering of the user interface, and so on. In order to reduce the power consumption speed of the device and ensure the fluency of users, the system will control the applications that fall back to the background, including process suspension (that is, the system no longer allocates CPU resources to the application process, and corresponding common events are no longer sent to the application process) and process termination.

The type of ▲ backend task is selected. The official developer of Tu Yuan Huawei can select the appropriate backend task according to the following features to meet the need for the application to continue running after it is retired to the background:

Short-term tasks: suitable for tasks that require high real-time performance and do not take a long time, for example, when you apply an update, you go back to the background and continue to update to save the data and status during the update.

Long-term tasks: suitable for user-aware tasks that run in the background for a long time, such as playing music in the background, navigation, device connection, etc., and use long-term tasks to avoid suspending the application process.

Deferred tasks: suitable for tasks with low real-time requirements and can be delayed. After retreating to the background, the application is put into the execution queue, and the system will schedule it according to memory, power consumption, etc., for example, when there is a network, it will take the initiative to obtain mail from time to time.

Agent reminder: agent reminder means that after the application is withdrawn from the background or the process is terminated, the system will remind the agent application accordingly. It is suitable for timing reminder business, and the types of reminders currently supported include countdown, calendar and alarm clock.

After the ▲ source Huawei official website selects the appropriate backend task type, the developer can apply for the backend task. Take the short-term task as an example, the steps for CTOnews.com are as follows:

1. Understand the relevant mechanisms and specifications to achieve more efficient development.

Application timing: the application needs to apply for a short-term task in the foreground or backstage within 5 seconds.

Quantity limit: a maximum of 3 applications are supported for one application at a time.

Quota mechanism: an application has a time quota of 10 minutes a day, a maximum of 3 minutes for a single quota, and a default of 1 minute when the power is low. You are not allowed to apply for short-term tasks after the quota has been consumed. Therefore, after the task is completed, the application needs to take the initiative to cancel the short-term task, otherwise it will affect the remaining quota of the short-term task on the day of the application.

Quota calculation: the timing of short-term tasks under the same application is not repeated only when it is applied in the background.

2. Import relevant modules, apply for short-term tasks and implement callback.

3. Query the remaining time of short-term tasks to determine whether to continue to run other businesses.

4. Cancel the short-term task in time after the task is completed.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

IT Information

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report