提交 ee9770c3 编写于 作者: G Gloria

Update docs against 13331+14265+14188+14253+14202

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 72b2d7eb
......@@ -48,7 +48,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
console.log('The ability has been started by the way of startAbility.');
}
}
}
......@@ -74,7 +74,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
console.log('The ability has exit last because the ability was not responding.');
}
}
}
......@@ -110,20 +110,22 @@ Enumerates the window modes in which an ability can be displayed at startup. It
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value| Description |
| --- | --- | --- |
| WINDOW_MODE_UNDEFINED | 0 | Undefined window mode. |
| WINDOW_MODE_FULLSCREEN | 1 | The ability is displayed in full screen. |
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. |
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. |
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The left screen in horizontal direction or the upper screen in vertical direction is the primary window. |
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The right screen in horizontal direction or the lower screen in vertical direction is the secondary window. |
| WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.|
**Example**
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.test.example',
abilityName: 'MainAbility'
};
let option = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
......@@ -131,9 +133,9 @@ let option = {
// Ensure that the context is obtained.
this.context.startAbility(want, option).then(()={
console.log("Succeed to start ability.");
console.log('Succeed to start ability.');
}).catch((error)=>{
console.log("Failed to start ability with error: " + JSON.stringify(error));
console.log('Failed to start ability with error: ' + JSON.stringify(error));
});
```
......@@ -157,7 +159,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onMemoryLevel(level) {
if (level === AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
console.log("The memory of device is critical, please release some memory.");
console.log('The memory of device is critical, please release some memory.');
}
}
}
......@@ -209,7 +211,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
if (reason === AbilityConstant.StateType.CONTINUATION) {
console.log("Save the ability data when the ability continuation.");
console.log('Save the ability data when the ability continuation.');
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
......
......@@ -49,14 +49,14 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.ohos.example',
abilityName: 'MainAbility'
};
abilityDelegator.startAbility(want, (err) => {
if (err.code !== 0) {
console.log("Success start ability.");
console.log('Success start ability.');
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
console.log('Failed start ability, error: ' + JSON.stringify(err));
}
})
```
......@@ -81,8 +81,8 @@ Obtains an [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments parameters:' + JSON.stringify(args.parameters));
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
```
......@@ -11,7 +11,7 @@ The **AbilityLifecycleCallback** module defines the callbacks to receive lifecyc
## Modules to Import
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback';
```
......@@ -25,15 +25,15 @@ Called when an ability is created.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
console.log('AbilityLifecycleCallback onAbilityCreate.');
}
};
```
......@@ -48,16 +48,16 @@ Called when the window stage of an ability is created.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
console.log('AbilityLifecycleCallback onWindowStageCreate.');
}
};
```
......@@ -72,16 +72,16 @@ Called when the window stage of an ability gains focus.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
console.log('AbilityLifecycleCallback onWindowStageActive.');
}
};
```
......@@ -96,16 +96,16 @@ Called when the window stage of an ability loses focus.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
console.log('AbilityLifecycleCallback onWindowStageInactive.');
}
};
```
......@@ -120,16 +120,16 @@ Called when the window stage of an ability is destroyed.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
console.log('AbilityLifecycleCallback onWindowStageDestroy.');
}
};
```
......@@ -144,15 +144,15 @@ Called when an ability is destroyed.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
console.log('AbilityLifecycleCallback onAbilityDestroy.');
}
};
```
......@@ -167,15 +167,15 @@ Called when an ability is switched from the background to the foreground.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
console.log('AbilityLifecycleCallback onAbilityForeground.');
}
};
```
......@@ -190,15 +190,15 @@ Called when an ability is switched from the foreground to the background.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
console.log('AbilityLifecycleCallback onAbilityBackground.');
}
};
```
......@@ -213,15 +213,15 @@ Called when an ability is continued on another device.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | Yes| **Ability** object.|
**Example**
```ts
let abilityLifecycleCallback = {
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
console.log('AbilityLifecycleCallback onAbilityContinue.');
}
};
```
......@@ -232,52 +232,52 @@ let abilityLifecycleCallback = {
MyFirstAbility.ts
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityStage from "@ohos.app.ability.AbilityStage";
import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback';
import AbilityStage from '@ohos.app.ability.AbilityStage';
import UIAbility from '@ohos.app.ability.UIAbility';
// Declare the ability lifecycle callbacks. A listener can be registered in applicationContext only after all the callbacks are configured.
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
console.log('AbilityLifecycleCallback onAbilityCreate.');
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
console.log('AbilityLifecycleCallback onWindowStageCreate.');
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
console.log('AbilityLifecycleCallback onWindowStageActive.');
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
console.log('AbilityLifecycleCallback onWindowStageInactive.');
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
console.log('AbilityLifecycleCallback onWindowStageDestroy.');
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
console.log('AbilityLifecycleCallback onAbilityDestroy.');
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
console.log('AbilityLifecycleCallback onAbilityForeground.');
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
console.log('AbilityLifecycleCallback onAbilityBackground.');
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
console.log('AbilityLifecycleCallback onAbilityContinue.');
}
};
export default class MyFirstAbility extends UIAbility {
onCreate() {
console.log("MyAbilityStage onCreate");
console.log('MyAbilityStage onCreate');
// 1. Obtain applicationContext through the context attribute.
let applicationContext = this.context.getApplicationContext();
// 2. Register the listener for the ability lifecycle changes through the applicationContext object.
try {
globalThis.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
globalThis.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback);
console.log('registerAbilityLifecycleCallback number: ' + JSON.stringify(lifecycleId));
} catch (paramError) {
console.log("error: " + paramError.code + " ," + paramError.message);
console.log('error: ' + paramError.code + ' ,' + paramError.message);
}
}
}
......@@ -285,17 +285,17 @@ export default class MyFirstAbility extends UIAbility {
MySecondAbility.ts
```ts
import UIAbility from "ohos.app.ability.UIAbility";
import UIAbility from 'ohos.app.ability.UIAbility';
export default class MySecondAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
// 3. Deregister the listener for the environment changes through the applicationContext object.
applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => {
// 3. Deregister the listener for the ability lifecycle changes through the applicationContext object.
applicationContext.off('abilityLifecycle', globalThis.lifecycleId, (error) => {
if (error.code != 0) {
console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error));
console.log('unregisterAbilityLifecycleCallback failed, error: ' + JSON.stringify(error));
} else {
console.log("unregisterAbilityLifecycleCallback success.");
console.log('unregisterAbilityLifecycleCallback success.');
}
});
}
......
......@@ -21,13 +21,14 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni
**System API**: This enum is an internal definition of a system API and cannot be called by third-party applications.
| Name| Value| Description|
| Name| Value| Description|
| -------- | -------- | -------- |
| INITIAL | 0 | The ability is in the initial state.|
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. |
| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. |
| INITIAL | 0 | The ability is in the initial state.|
| FOCUS | 2 | The ability has the focus.|
| FOREGROUND | 9 | The ability is in the foreground state. |
| BACKGROUND | 10 | The ability is in the background state. |
| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. |
| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. |
## updateConfiguration
......@@ -38,7 +39,7 @@ Updates the configuration. This API uses an asynchronous callback to return the
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory | Description |
......@@ -71,9 +72,9 @@ const config = {
try {
abilityManager.updateConfiguration(config, (err) => {
if (err.code !== 0) {
console.log("updateConfiguration fail, err: " + JSON.stringify(err));
console.log('updateConfiguration fail, err: ' + JSON.stringify(err));
} else {
console.log("updateConfiguration success.");
console.log('updateConfiguration success.');
}
})
} catch (paramError) {
......@@ -142,7 +143,7 @@ try {
getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
Obtains the ability running information. This API uses an asynchronous callback to return the result.
Obtains the UIAbility running information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
......@@ -152,7 +153,7 @@ Obtains the ability running information. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Yes | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback. |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Yes | Callback used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in this callback. |
**Error codes**
......@@ -170,9 +171,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos((err, data) => {
if (err.code !== 0) {
console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
console.log('getAbilityRunningInfos fail, error: ' + JSON.stringify(err));
} else {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data));
console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data));
}
});
} catch (paramError) {
......@@ -185,7 +186,7 @@ try {
getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
Obtains the ability running information. This API uses a promise to return the result.
Obtains the UIAbility running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
......@@ -195,7 +196,7 @@ Obtains the ability running information. This API uses a promise to return the r
| Type | Description |
| ---------------------------------------- | ------- |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Callback used to return the API call result and the ability running information. You can perform error handling or custom processing in this callback.|
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -212,9 +213,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos fail, err: " + JSON.stringify(err));
console.log('getAbilityRunningInfos fail, err: ' + JSON.stringify(err));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
......@@ -257,9 +258,9 @@ let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
if (err.code !== 0) {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
} else {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}
});
} catch (paramError) {
......@@ -273,7 +274,7 @@ try {
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
Obtains the ExtensionAbility running information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
......@@ -307,9 +308,9 @@ let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
......@@ -346,9 +347,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility((err, data) => {
if (err.code !== 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
console.log('getTopAbility fail, err: ' + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
console.log('getTopAbility success, data: ' + JSON.stringify(data));
}
});
```
......@@ -358,7 +359,7 @@ abilityManager.getTopAbility((err, data) => {
getTopAbility(): Promise\<ElementName>;
Obtains the top ability, which is the ability that has the window focus. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Return value**
......@@ -381,8 +382,8 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility success, data: " + JSON.stringify(data));
console.log('getTopAbility success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
console.log('getTopAbility fail, err: ' + JSON.stringify(err));
})
```
......@@ -30,7 +30,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
console.log('MyAbilityStage.onCreate is called');
}
}
```
......@@ -63,8 +63,8 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
console.log('MyAbilityStage.onAcceptWant called');
return 'com.example.test';
}
}
```
......
......@@ -41,9 +41,9 @@ import appManager from '@ohos.app.ability.appManager';
appManager.isRunningInStabilityTest((err, flag) => {
if (err.code !== 0) {
console.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err));
console.log('isRunningInStabilityTest faile, err: ' + JSON.stringify(err));
} else {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}
})
```
......@@ -77,9 +77,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import appManager from '@ohos.app.ability.appManager';
appManager.isRunningInStabilityTest().then((flag) => {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -112,9 +112,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import appManager from '@ohos.app.ability.appManager';
appManager.isRamConstrainedDevice().then((data) => {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -147,9 +147,9 @@ import appManager from '@ohos.app.ability.appManager';
appManager.isRamConstrainedDevice((err, data) => {
if (err.code !== 0) {
console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err));
console.log('isRamConstrainedDevice faile, err: ' + JSON.stringify(err));
} else {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}
})
```
......@@ -182,9 +182,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import appManager from '@ohos.app.ability.appManager';
appManager.getAppMemorySize().then((data) => {
console.log("The size of app memory is:" + JSON.stringify(data));
console.log('The size of app memory is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -217,16 +217,16 @@ import appManager from '@ohos.app.ability.appManager';
appManager.getAppMemorySize((err, data) => {
if (err.code !== 0) {
console.log("getAppMemorySize faile, err: " + JSON.stringify(err));
console.log('getAppMemorySize faile, err: ' + JSON.stringify(err));
} else {
console.log("The size of app memory is:" + JSON.stringify(data));
console.log('The size of app memory is:' + JSON.stringify(data));
}
})
```
## appManager.getProcessRunningInformation
## appManager.getRunningProcessInformation
getProcessRunningInformation(): Promise\<Array\<ProcessRunningInformation>>;
getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>;
Obtains information about the running processes. This API uses a promise to return the result.
......@@ -234,13 +234,11 @@ Obtains information about the running processes. This API uses a promise to retu
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -255,16 +253,16 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import appManager from '@ohos.app.ability.appManager';
appManager.getProcessRunningInformation().then((data) => {
console.log("The process running information is:" + JSON.stringify(data));
appManager.getRunningProcessInformation().then((data) => {
console.log('The running process information is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
## appManager.getProcessRunningInformation<sup>9+</sup>
## appManager.getRunningProcessInformation<sup>9+</sup>
getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInformation>>): void;
getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void;
Obtains information about the running processes. This API uses an asynchronous callback to return the result.
......@@ -272,13 +270,11 @@ Obtains information about the running processes. This API uses an asynchronous c
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Type| Description|
| -------- | -------- |
|AsyncCallback\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
|AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.|
**Error codes**
......@@ -293,18 +289,18 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
```ts
import appManager from '@ohos.app.ability.appManager';
appManager.getProcessRunningInformation((err, data) => {
appManager.getRunningProcessInformation((err, data) => {
if (err.code !== 0) {
console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err));
console.log('getRunningProcessInformation faile, err: ' + JSON.stringify(err));
} else {
console.log("The process running information is:" + JSON.stringify(data));
console.log('The process running information is:' + JSON.stringify(data));
}
})
```
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver): number;
on(type: 'applicationState', observer: ApplicationStateObserver): number;
Registers an observer to listen for the state changes of all applications.
......@@ -318,7 +314,7 @@ Registers an observer to listen for the state changes of all applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
**Return value**
......@@ -367,7 +363,7 @@ try {
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
Registers an observer to listen for the state changes of a specified application.
......@@ -381,7 +377,7 @@ Registers an observer to listen for the state changes of a specified application
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.|
| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
......@@ -423,7 +419,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
const observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -432,7 +428,7 @@ try {
## appManager.off
off(type: "applicationState", observerId: number, callback: AsyncCallback\<void>): void;
off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void;
Deregisters the application state observer. This API uses an asynchronous callback to return the result.
......@@ -446,7 +442,7 @@ Deregisters the application state observer. This API uses an asynchronous callba
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
| observerId | number | Yes| Digital code of the observer.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.|
......@@ -485,7 +481,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -494,13 +490,13 @@ try {
// 2. Deregister the application state observer.
function unregisterApplicationStateObserverCallback(err) {
if (err.code !== 0) {
console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err));
console.log('unregisterApplicationStateObserverCallback faile, err: ' + JSON.stringify(err));
} else {
console.log("unregisterApplicationStateObserverCallback success.");
console.log('unregisterApplicationStateObserverCallback success.');
}
}
try {
appManager.off("applicationState", observerId, unregisterApplicationStateObserverCallback);
appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
......@@ -508,7 +504,7 @@ try {
## appManager.off
off(type: "applicationState", observerId: number): Promise\<void>;
off(type: 'applicationState', observerId: number): Promise\<void>;
Deregisters the application state observer. This API uses an asynchronous callback to return the result.
......@@ -522,7 +518,7 @@ Deregisters the application state observer. This API uses an asynchronous callba
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the API to call. It is fixed at **"applicationState"**.|
| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.|
| observerId | number | Yes| Digital code of the observer.|
**Return value**
......@@ -566,7 +562,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -574,10 +570,10 @@ try {
// 2. Deregister the application state observer.
try {
appManager.off("applicationState", observerId).then((data) => {
console.log("unregisterApplicationStateObserver success, data: " + JSON.stringify(data));
appManager.off('applicationState', observerId).then((data) => {
console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("unregisterApplicationStateObserver faile, err: " + JSON.stringify(err));
console.log('unregisterApplicationStateObserver faile, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
......@@ -617,15 +613,15 @@ import appManager from '@ohos.app.ability.appManager';
function getForegroundApplicationsCallback(err, data) {
if (err.code !== 0) {
console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
console.log('getForegroundApplicationsCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
console.log('getForegroundApplicationsCallback success, data: ' + JSON.stringify(data));
}
}
try {
appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -661,9 +657,9 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
import appManager from '@ohos.app.ability.appManager';
appManager.getForegroundApplications().then((data) => {
console.log("getForegroundApplications success, data: " + JSON.stringify(data));
console.log('getForegroundApplications success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getForegroundApplications fail, err: " + JSON.stringify(err));
console.log('getForegroundApplications fail, err: ' + JSON.stringify(err));
})
```
......@@ -703,12 +699,12 @@ let bundleName = 'bundleName';
let accountId = 0;
try {
appManager.killProcessWithAccount(bundleName, accountId).then(() => {
console.log("killProcessWithAccount success");
console.log('killProcessWithAccount success');
}).catch((err) => {
console.log("killProcessWithAccount fail, err: " + JSON.stringify(err));
console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.error('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -750,9 +746,9 @@ let bundleName = 'bundleName';
let accountId = 0;
function killProcessWithAccountCallback(err, data) {
if (err.code !== 0) {
console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err));
console.log('killProcessWithAccountCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("killProcessWithAccountCallback success.");
console.log('killProcessWithAccountCallback success.');
}
}
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
......@@ -793,15 +789,15 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err.code !== 0) {
console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err));
console.log('killProcessesByBundleNameCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("killProcessesByBundleNameCallback success.");
console.log('killProcessesByBundleNameCallback success.');
}
}
try {
appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -845,12 +841,12 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName).then((data) => {
console.log("killProcessesByBundleName success.");
console.log('killProcessesByBundleName success.');
}).catch((err) => {
console.log("killProcessesByBundleName fail, err: " + JSON.stringify(err));
console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -889,15 +885,15 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err) {
console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err));
console.log('clearUpApplicationDataCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("clearUpApplicationDataCallback success.");
console.log('clearUpApplicationDataCallback success.');
}
}
try {
appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -941,12 +937,12 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName).then((data) => {
console.log("clearUpApplicationData success.");
console.log('clearUpApplicationData success.');
}).catch((err) => {
console.log("clearUpApplicationData fail, err: " + JSON.stringify(err));
console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......
......@@ -18,13 +18,12 @@ Enumerates the application restart flags. This enum is used as an input paramete
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALWAYS_RESTART | 0 | The application is restarted in all cases.|
| CPP_CRASH_NO_RESTART | 0x0001 | The application is not restarted in the case of CPP_CRASH.|
| JS_CRASH_NO_RESTART | 0x0002 | The application is not restarted in the case of JS_CRASH.|
| APP_FREEZE_NO_RESTART | 0x0004 | The application is not restarted in the case of APP_FREEZE.|
| NO_RESTART | 0xFFFF | The application is not restarted in any case.|
| Name | Value | Description |
| ---------- | ---- | ---------- |
| ALWAYS_RESTART | 0 | The application is restarted in all cases.|
| RESTART_WHEN_JS_CRASH | 0x0001 | The application is restarted in the case of JS_CRASH.|
| RESTART_WHEN_APP_FREEZE | 0x0002 | The application is restarted in the case of APP_FREEZE.|
| NO_RESTART | 0xFFFF | The application is not restarted in any case.|
## appRecovery.SaveOccasionFlag
......@@ -69,9 +68,8 @@ Enables application recovery.
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import AbilityStage from '@ohos.app.ability.AbilityStage';
import UIAbility from '@ohos.app.ability.UIAbility';
export default class MyAbility extends UIAbility {
export default class MyAbilityStage extends AbilityStage {
onCreate() {
appRecovery.enableAppRecovery(
appRecovery.RestartFlag::ALWAYS_RESTART,
......@@ -99,15 +97,15 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.restartApp();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -133,14 +131,14 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.saveAppState();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
# @ohos.app.ability.StartOptions (StartOptions)
**StartOptions** is used as an input parameter of [startAbility()](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability-1) to specify the window mode of an ability.
The **StartOptions** module implements ability startup options.
> **NOTE**
>
......@@ -18,7 +18,38 @@ import StartOptions from '@ohos.app.ability.StartOptions';
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| [windowMode](js-apis-application-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.|
| displayId | number | No| Display ID. The default value is **0**, indicating the current display.|
| [windowMode](js-apis-app-ability-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.|
| displayId | number | No| Display ID.|
**Example**
```ts
import missionManager from '@ohos.app.ability.missionManager';
try {
missionManager.getMissionInfos('', 10, (error, missions) => {
if (error.code) {
console.log('getMissionInfos failed, error.code:' + JSON.stringify(error.code) +
'error.message:' + JSON.stringify(error.message));
return;
}
console.log('size = ' + missions.length);
console.log('missions = ' + JSON.stringify(missions));
let id = missions[0].missionId;
let startOptions = {
windowMode : 101,
displayId: 0
};
missionManager.moveMissionToFront(id, startOptions).then(() => {
console.log('moveMissionToFront is called ');
});
});
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册