has.restartAtomicService
has.restartAtomicService(Object object)
Restarts the current atomic service.
Since: 1.0.21
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
| path | string | No | Path of the page to be opened. Parameters can be appended to the path in the following format: a question mark (?) between a parameter and the path; an equal sign (=) between a parameter and its value; ampersands (&) between multiple parameters. You can obtain the query parameter in the callbacks of App.onLaunch, App.onShow, and Page.onLoad of an atomic service. Supported format: - If path is empty, the home page is displayed. - If path is not empty, the page path must be the code package path defined in the app.json file. For example, if page/path/path is defined in the app.json file, the valid in-app page path is page/path/path?key1=value1&key2=value2. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
| 102 | Parameter error. Possible causes: check type is invalid. |
| 20000901 | restartAtomicService:fail. For details, see Ability Error Codes. |
Example:
has.restartAtomicService({
path: 'page/path/path?key1=value1&key2=value2',
success: (res) => {
console.info('restartAtomicService success:', res);
},
fail: (err) => {
console.error('restartAtomicService fail:', err);
},
complete: (res) => {
console.info('restartAtomicService complete:', res);
}
}); has.navigateToAtomicService
has.navigateToAtomicService(Object object)
Opens another atomic service.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
| appId | string | Yes | Application ID of the atomic service to be opened. |
| path | string | No | Path of the page to open, which is used only for atomic services developed based on ASCF. Parameters can be appended to the path in the following format: a question mark (?) between a parameter and the path; an equal sign (=) between a parameter and its value; ampersands (&) between multiple parameters. You can obtain the query parameter in the callbacks of App.onLaunch, App.onShow, and Page.onLoad of an atomic service. Supported format: - If path is empty, the home page is displayed. - If path is not empty, the page path must be the code package path defined in the app.json file. For example, if page/path/path is defined in the app.json file, the valid in-app page path is page/path/path?key1=value1&key2=value2. |
| extraData | Object | No | Data to be passed to the target atomic service, which is used only for atomic services developed based on ASCF. |
| wantParam | Object | No | ArkTS startup parameter. The following fields are reserved for the system and should not be used: ascfPara: reserved for ASCF. subPackageName: subpackage to preload. It is used for installing the main package and corresponding subpackages at a time when the atomic service subpackage is started. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
| 102 | Parameter error. Possible causes: 1.appId is required. 2.check type is invalid. |
| 20000601 | navigateToAtomicService error. For details, see Ability Error Codes. |
Example:
has.navigateToAtomicService({
appId: 'xxxx', // Application ID of the target atomic service
path: 'pages/index/index',
extraData: {
data: 'extraData'
},
success: () => {
console.info('navigateToAtomicService success!');
},
fail: (err) => {
console.error('navigateToAtomicService fail:', err);
},
complete: (res) => {
console.info('navigateToAtomicService complete:', res);
}
}); has.navigateBackAtomicService
has.navigateBackAtomicService(Object object)
Returns to the previous atomic service. This API can be successfully called only when the current atomic service is opened by another atomic service.
Since: 1.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
| extraData | Object | No | Data carried when the previous atomic service is returned. |
| wantParam | Object | No | ArkTS startup parameter. The following fields are reserved for the system and should not be used: ascfPara: reserved for ASCF. subPackageName: subpackage to preload. It is used for installing the main package and corresponding subpackages at a time when the atomic service subpackage is started. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
| 102 | Parameter error. Possible causes: check type is invalid. |
| 20000701 | navigateBackAtomicService error. For details, see Ability Error Codes. |
Example:
has.navigateBackAtomicService({
extraData: {
data: 'extraData'
},
success: () => {
console.info('navigateBackAtomicService success!');
},
fail: (err) => {
console.error('navigateBackAtomicService fail:', err);
},
complete: (res) => {
console.info('navigateBackAtomicService complete:', res);
}
}); has.terminateSelf
has.terminateSelf(Object object)
Exits the current atomic service. When the current atomic service is started in the half-screen mode via the open-embedded-atomicservice component, calling this method to exit will return a result to the launcher.
Since: 1.0.18
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
| resultCode | number | No | Result code returned to the launcher. |
| params | Object | No | Data returned to the launcher. If params is not empty, resultCode must be non-empty. Otherwise, params will be ignored. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
| 102 | Parameter error. Possible causes: check type is invalid. |
| 20000801 | terminateSelf error. For details, see Ability Error Codes. |
Example:
has.terminateSelf({
resultCode: 100, // Custom result code.
params: {
data: 'test' // Custom parameter to send.
},
success: () => {
console.info('terminateSelf success!');
},
fail: (err) => {
console.error('terminateSelf fail:', err);
},
complete: (res) => {
console.info('terminateSelf complete:', res);
}
});