start
Start from API_LEVEL
3.0. Please refer to API_LEVEL.
Start the specified background service, call it asynchronously and return the result through the callback function.
info
permission code: device:os.bg_service
Type
function start(option: Option): Result
Parameters
Option
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| file | string | Y | - | The background service js file must be the one configured in the service module in app.json | 3.0 |
| param | string | N | - | Parameters passed in when the js file is loaded by the backend service | 3.0 |
| complete_func | (callbackOption: CallbackOption) => void | Y | - | Callback function for the completion of the backend service start | 3.0 |
CallbackOption
| Property | Type | Description | API_LEVEL |
|---|---|---|---|
| file | string | Background service js file, same as start incoming parameters | 3.0 |
| result | boolean | Background service start result, true means success, false means failure | 3.0 |
Result
| Type | Description |
|---|---|
boolean | If 0 is returned, the background service was started successfully. |
ERROR_CODE
| Value | Type | Description | API_LEVEL |
|---|---|---|---|
| 0 | number | Success | 3.0 |
| 1 | number | Parameter error | 3.0 |
| 2 | number | Service Status Error | 3.0 |
| 3 | number | No Permission | 3.0 |
| 4 | number | No Memory | 3.0 |
| 5 | number | Not Support | 3.0 |
| 6 | number | Prohibited | 3.0 |
| 7 | number | The number of services has reached the system limit | 3.0 |
| 255 | number | Unknown Error | 3.0 |
Example
import { start } from '@zos/app-service'