Generally, resources occupied by quick apps will be released after the apps are switched to the background. However, users of apps such as those related to music and sports hope that these apps can still run in the background and provide services. To meet this requirement, background running is supported.
There are two ways for switching a quick app to the background:
- Tap the Home button to access the home screen. Huawei Quick App Engine will run the quick app in the background without any additional configurations.
- Tap the Back button to exit the quick app. The quick app continues to run in the background only if the following conditions are met at the same time:
- The manifest.json file declares required background running APIs.
- The current page is the first page opened in a quick app.
- At least one background running API (declared in manifest.json) is running.
Suggestions
- Running an app in the background consumes a large number of system resources. Quick apps should use only necessary resources.
- It is recommended that the APIs that need to run in the background be placed in app.ux to avoid the impact of page switching and destruction. You can declare the audio module on all the pages that involve music playing. On each page, use the onshow function to implement the callback functions such as music changing, pausing, and playback.
Configuration Method
Declare the required background running APIs in the manifest.json file, including:
- system.audio: plays audio.
- system.record: records voice.
- system.request: uploads or downloads data.
- system.geolocation: obtains the location.
{
"package": "com.huawei.sample",
......
"config": {
"logLevel": "trace",
"background": {
"features":[
"system.audio",
"system.record",
"system.request",
"system.geolocation"
]
}
......
} [h2]APIs That Need to Be Applied for
These APIs must be declared in background of the manifest.json file. A quick app will run in the background only if one of the following APIs is called when a user exits the quick app: system.audio, system.record, system.geolocation, and system.request.
[h2]APIs That Can Be Directly Called
All APIs can be directly called when a quick app is running in the background.
Differences from Implementations in the Vendor Alliance
[h2]APIs
resident.start and resident.stop are both empty implementations. If you want to use an API, apply for them in the manifest.json file.
[h2]Notification Bar
- The text passed in resident.start is not displayed on the notification bar.
- All background-running notifications use the same notification bar message based on specifications formulated by the vendor alliance. System notifications are used for recording and downloading, and no notification is displayed for uploading. Notifications of the location service are sent by Huawei Quick App Engine itself.
[h2]Stop Running an App in the Background
Huawei will not stop an app when the app run in the background for 20s.