@@ -7,6 +7,12 @@ This is the base class of [UIAbility](js-apis-app-ability-uiAbility.md) and [Ext
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
|AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
**Error codes**
...
...
@@ -59,9 +59,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.|
**Error codes**
...
...
@@ -94,9 +94,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
**Error codes**
...
...
@@ -128,9 +128,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters**
| Type| Description|
| -------- | -------- |
| AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
| Type| Description|
| -------- | -------- |
| AsyncCallback<boolean> |Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.|
**Error codes**
...
...
@@ -164,9 +164,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
**Error codes**
...
...
@@ -198,9 +198,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
| Type| Description|
| -------- | -------- |
|AsyncCallback<number> |Callback used to return the API call result and the memory size. You can perform error handling or custom processing in this callback.|
**Error codes**
...
...
@@ -641,7 +641,7 @@ Obtains applications that are running in the foreground. This API uses a promise
| Type| Description|
| -------- | -------- |
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data|
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | Promise used to return an array holding the application state data. |
Kills a process by bundle name and account ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
> **NOTE**
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
@@ -66,7 +66,7 @@ Applies a quick fix patch. This API uses an asynchronous callback to return the
| ID| Error Message|
| ------- | -------- |
| 18500002 | Copy file failed, maybe not exist or inaccessible. |
| 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
| 18500008 | Internal error. |
If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9). The table below lists the possible error codes and messages.
...
...
@@ -130,7 +130,7 @@ Applies a quick fix patch. This API uses a promise to return the result.
| ID| Error Message|
| ------- | -------- |
| 18500002 | Copy file failed, maybe not exist or inaccessible. |
| 18500002 | The specified quick fix is invalid. It may not exist or inaccessible. |
| 18500008 | Internal error. |
If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_APPLY_RESULT](commonEvent-definitions.md#common_event_quick_fix_apply_result9). The table below lists the possible error codes and messages.
...
...
@@ -183,7 +183,7 @@ Obtains the quick fix information of the application. This API uses an asynchron
| ID| Error Message|
| ------- | -------- |
| 18500001 | The bundle is not exist. |
| 18500001 | The specified bundleName is invalid. |
| 18500008 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
...
...
@@ -233,7 +233,7 @@ Obtains the quick fix information of the application. This API uses a promise to
| ID| Error Message|
| ------- | -------- |
| 18500001 | The bundle is not exist. |
| 18500001 | The specified bundleName is invalid. |
| 18500008 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
...
...
@@ -252,3 +252,102 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Name of the bundle for which the patch needs to be revoked.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 18500001 | The bundle is not exist or no patch has applied. |
| 18500009 | The application has a apply quick fix task that is being processed. |
If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_REVOKE_RESULT](./common_event/commonEvent-ability.md#common_event_quick_fix_revoke_result10). The table below lists the possible error codes and messages.
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Parameter| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Name of the bundle for which the patch needs to be revoked.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
| ID| Error Message|
| ------- | -------- |
| 18500001 | The bundle is not exist or no patch has applied. |
| 18500009 | The application has a apply quick fix task that is being processed. |
If an error occurs during patch installation, the error code and message are returned through the common event [COMMON_EVENT_QUICK_FIX_REVOKE_RESULT](./common_event/commonEvent-ability.md#common_event_quick_fix_revoke_result10). The table below lists the possible error codes and messages.
The **ServiceExtensionAbility** module provides lifecycle callbacks when a ServiceExtensionAbility (background service) is created, destroyed, connected, or disconnected.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.
## Modules to Import
...
...
@@ -145,6 +146,29 @@ Called following **onCreate()** when a ServiceExtensionAbility is started by cal
}
```
If the returned **RemoteObject** object depends on an asynchronous API, you can use the asynchronous lifecycle.
@@ -172,6 +196,17 @@ Called when a client is disconnected from this ServiceExtensionAbility.
}
```
After the **onDisconnect** lifecycle callback is executed, the application may exit. As a result, the asynchronous function in **onDisconnect** may fail to be executed correctly, for example, asynchronously writing data to the database. The asynchronous lifecycle can be used to ensure that the subsequent lifecycle continues after the asynchronous **onDisconnect** is complete.
@@ -132,6 +132,7 @@ Called when this UIAbility is destroyed to clear resources.
**Example**
```ts
classMyUIAbilityextendsUIAbility{
onDestroy(){
...
...
@@ -140,6 +141,16 @@ Called when this UIAbility is destroyed to clear resources.
}
```
After the **onDestroy** lifecycle callback is executed, the application may exit. As a result, the asynchronous function in **onDestroy** may fail to be executed correctly, for example, asynchronously writing data to the database. The asynchronous lifecycle can be used to ensure that the subsequent lifecycle continues after the asynchronous **onDestroy** is complete.
```ts
classMyUIAbilityextendsUIAbility{
asynconDestroy(){
console.log('onDestroy');
// Call the asynchronous function.
}
}
```
## UIAbility.onForeground
...
...
@@ -360,7 +371,7 @@ Sends sequenceable data to the target ability.
| ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
...
...
@@ -441,7 +452,7 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
| ------- | -------------------------------- |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
| 16000050 | Internal error. |
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
...
...
@@ -586,9 +597,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
@@ -26,7 +26,7 @@ import Want from '@ohos.app.ability.Want';
| entities | Array\<string> | No| Additional category information (such as browser and video player) of the ability. It is a supplement to the **action** field for implicit Want. and is used to filter ability types.|
| uri | string | No| Data carried. This field is used together with **type** to specify the data type. If **uri** is specified in a Want, the Want will match the specified URI information, including **scheme**, **schemeSpecificPart**, **authority**, and **path**.|
| type | string | No| MIME type, that is, the type of the file to open, for example, **'text/xml'** and **'image/*'**. For details about the MIME type definition, see https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com.|
| parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerBundleName**: bundle name of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br>- **ohos.dlp.params.sandbox**: available only for DLP files.|
| parameters | {[key: string]: any} | No | Want parameters in the form of custom key-value (KV) pairs. By default, the following keys are carried:<br>- **ohos.aafwk.callerPid**: PID of the caller.<br>- **ohos.aafwk.param.callerBundleName**: bundle name of the caller.<br>- **ohos.aafwk.param.callerToken**: token of the caller.<br>- **ohos.aafwk.param.callerUid**: UID in [BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1), that is, the application UID in the bundle information.<br>- **component.startup.newRules**: whether to enable the new control rule.<br>- **moduleName**: module name of the caller. No matter what this field is set to, the correct module name will be sent to the peer.<br>- **ohos.dlp.params.sandbox**: available only for DLP files.<br>- **ability.params.backToOtherMissionStack**: whether to support redirection back across mission stacks.|
| [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | No| How the **Want** object will be handled. By default, a number is passed in.<br>For example, **wantConstant.Flags.FLAG_ABILITY_CONTINUATION** specifies whether to start the ability in cross-device migration scenarios.|
**Example**
...
...
@@ -34,7 +34,8 @@ import Want from '@ohos.app.ability.Want';
- Basic usage: called in a UIAbility object, as shown in the example below. For details about how to obtain the context, see [Obtaining the Context of UIAbility](../../application-models/uiability-usage.md#obtaining-the-context-of-uiability).
'deviceId':'',// An empty deviceId indicates the local device.
'bundleName':'com.example.myapplication',
...
...
@@ -52,7 +53,8 @@ import Want from '@ohos.app.ability.Want';
* String
```ts
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
...
...
@@ -67,7 +69,8 @@ import Want from '@ohos.app.ability.Want';
```
* Number
```ts
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
...
...
@@ -83,7 +86,8 @@ import Want from '@ohos.app.ability.Want';
```
* Boolean
```ts
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
...
...
@@ -98,7 +102,8 @@ import Want from '@ohos.app.ability.Want';
```
* Object
```ts
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
...
...
@@ -118,7 +123,8 @@ import Want from '@ohos.app.ability.Want';
```
* Array
```ts
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
...
...
@@ -138,7 +144,8 @@ import Want from '@ohos.app.ability.Want';
```ts
import fs from '@ohos.file.fs';
let context = ...; // UIAbilityContext
import common from '@ohos.app.ability.common';
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let fd;
try {
...
...
@@ -160,3 +167,33 @@ import Want from '@ohos.app.ability.Want';
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
});
```
- Usage of **parameters**: The following uses **ability.params.backToOtherMissionStack** as an example. When a ServiceExtensionAbility starts a UIAbility, redirection back across mission stacks is supported.
```ts
// (1) UIAbility1 starts a ServiceExtensionAbility.
let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want = {
bundleName: 'com.example.myapplication1',
abilityName: 'ServiceExtensionAbility',
};
context.startAbility(want, (err) => {
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
});
// (2) The ServiceExtensionAbility starts UIAbility2, carrying **"ability.params.backToOtherMissionStack": true** during the startup.
let context = ...; // ServiceExtensionContext
let want = {
bundleName: 'com.example.myapplication2',
abilityName: 'MainAbility',
parameters: {
"ability.params.backToOtherMissionStack": true,
},
};
context.startAbility(want, (err) => {
console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
});
```
Note: In the preceding example, when the ServiceExtensionAbility starts UIAbility2, **"ability.params.backToOtherMissionStack": true** is carried, indicating that redirection back across mission stacks is supported. Therefore, when you press **Back** on the page of UIAbility 2, the page of UIAbility1 page is displayed. However, if **ability.params.backToOtherMissionStack** is not carried or if **"ability.params.backToOtherMissionStack": false** is carried, the page of UIAbility1 is not displayed when you press **Back** on the page of UIAbility 2.
| DLP_PARAMS_SANDBOX | ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications.|
...
...
@@ -23,10 +25,11 @@ Defines **Params** (specifying the action that can be performed) in the Want.
| DLP_PARAMS_MODULE_NAME | ohos.dlp.params.moduleName | Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_ABILITY_NAME | ohos.dlp.params.abilityName | Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| DLP_PARAMS_INDEX | ohos.dlp.params.index | Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| ABILITY_RECOVERY_RESTART | ohos.ability.params.abilityRecoveryRestart | Action of recovering an ability from a fault and restarting it.|
| CONTENT_TITLE_KEY | ohos.extra.param.key.contentTitle | Action of sharing the content title.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| SHARE_ABSTRACT_KEY | ohos.extra.param.key.shareAbstract | Action of sharing the abstract.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| SHARE_URL_KEY | ohos.extra.param.key.shareUrl | Action of sharing the URL.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| ABILITY_BACK_TO_OTHER_MISSION_STACK | ability.params.backToOtherMissionStack | Whether to support redirection back across mission stacks.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| ABILITY_RECOVERY_RESTART<sup>10+</sup> | ohos.ability.params.abilityRecoveryRestart | Action of recovering an ability from a fault and restarting it.|
| CONTENT_TITLE_KEY<sup>10+</sup> | ohos.extra.param.key.contentTitle | Action of sharing the content title. |
| SHARE_ABSTRACT_KEY<sup>10+</sup> | ohos.extra.param.key.shareAbstract | Action of sharing the abstract. |
| SHARE_URL_KEY<sup>10+</sup> | ohos.extra.param.key.shareUrl | Action of sharing the URL. |
| DEVICE_ID_KEY | 'ohos.extra.param.key.device_id' <br>**System API**: This is a system API and cannot be called by third-party applications. | Device ID. |
| BUNDLE_NAME_KEY | 'ohos.extra.param.key.bundle_name' | Key that specifies the target bundle name.|
| LAUNCH_REASON_KEY<sup>10+</sup> | 'ohos.extra.param.key.form_launch_reason' | Reason for creating the widget. |
Kills a process by bundle name and account ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
> **NOTE**
>
> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user.
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS (required only when the account ID is not the current user) and ohos.permission.CLEAN_BACKGROUND_PROCESSES
**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
The **Configuration** module defines environment change information. **Configuration** is an interface definition and is used only for field declaration.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This module is deprecated since API version 9. You are advised to use [@ohos.app.ability.Configuration](js-apis-app-ability-configuration.md) instead.
The **ContinueCallback** module defines the callback function that indicates the result of mission continuation. For details about mission continuation, see [continueMission](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The **ContinueDeviceInfo** module defines the parameters required for initiating mission continuation. For details about mission continuation, see [continueMission](js-apis-distributedMissionManager.md#distributedmissionmanagercontinuemission).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The **MissionCallback** module defines the callbacks invoked after synchronization starts. These callbacks can be used as input parameters in [registerMissionListener](js-apis-distributedMissionManager.md#distributedmissionmanagerregistermissionlistener).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The **MissionParameter** module defines the parameters required for mission synchronization. It can be used an input parameter in [startSyncRemoteMissions](js-apis-distributedMissionManager.md#distributedmissionmanagerstartsyncremotemissions).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.