diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md index 766636a7c7d4cda38cb2b71395fd3f2575e2f784..62d38c714940a754e566bbdebadac2e3fcbccec2 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityConstant.md @@ -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.example.myapplication', + abilityName: 'EntryAbility' }; 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; } diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md index 5cfa437047868a9183ae4bb4f41ff42eec47f5d7..fe6bec9f550bef9bdeb6a3c61c8a1c5adc810f10 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityDelegatorRegistry.md @@ -49,16 +49,16 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); let want = { - bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + bundleName: 'com.example.myapplication', + abilityName: 'EntryAbility' }; abilityDelegator.startAbility(want, (err) => { - if (err.code !== 0) { - console.log("Success start ability."); + if (!err || err.code === 0) { + console.log('Success start ability.'); } else { - console.log("Failed start ability, error: " + JSON.stringify(err)); + console.log('Failed start ability, error: ${JSON.stringify(err)}'); } -}) +}); ``` ## AbilityDelegatorRegistry.getArguments @@ -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}'); ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md index 84be19350707fee37328ff8040b2986588afd2f8..df7b07b2d0303bf9310cfdd354d50b1db9239ece 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityLifecycleCallback.md @@ -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) => { - if (error.code != 0) { - console.log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error)); + // 3. Deregister the listener for the ability lifecycle changes through the applicationContext object. + applicationContext.off('abilityLifecycle', globalThis.lifecycleId, (error) => { + if (error && error.code !== 0) { + console.log('unregisterAbilityLifecycleCallback fail, error: ${JSON.stringify(error)}'); } else { - console.log("unregisterAbilityLifecycleCallback success."); + console.log('unregisterAbilityLifecycleCallback success.'); } }); } diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md index f7f9c49a4cdf1c9e8c92ad8b7c8bd977df525477..1752be21e6c0565bf1b8487fa1c447a758827929 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityManager.md @@ -24,6 +24,7 @@ Enumerates the ability states. This enum can be used together with [AbilityRunni | Name| Value| Description| | -------- | -------- | -------- | | 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. | @@ -70,15 +71,14 @@ const config = { try { abilityManager.updateConfiguration(config, (err) => { - if (err.code !== 0) { - console.log("updateConfiguration fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('updateConfiguration fail, err: ${JSON.stringify(err)}'); } else { - console.log("updateConfiguration success."); + console.log('updateConfiguration success.'); } }) } catch (paramError) { - console.log('error.code: ' + JSON.stringify(paramError.code) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -130,11 +130,10 @@ try { abilityManager.updateConfiguration(config).then(() => { console.log('updateConfiguration success.'); }).catch((err) => { - console.log('updateConfiguration fail, err: ' + JSON.stringify(err)); + console.log('updateConfiguration fail, err: ${JSON.stringify(err)}'); }) } catch (paramError) { - console.log('error.code: ' + JSON.stringify(paramError.code) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -169,15 +168,14 @@ import abilityManager from '@ohos.app.ability.abilityManager'; try { abilityManager.getAbilityRunningInfos((err, data) => { - if (err.code !== 0) { - console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err)); + if (err && err.code !== 0) { + 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) { - console.log('error.code: ' + JSON.stringify(paramError.code) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -185,7 +183,7 @@ try { getAbilityRunningInfos(): Promise\> -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 +193,7 @@ Obtains the ability running information. This API uses a promise to return the r | Type | Description | | ---------------------------------------- | ------- | -| Promise\> | 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\> | 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,13 +210,12 @@ 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) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -256,15 +253,14 @@ let upperLimit = 10; try { abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => { - if (err.code !== 0) { - console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + 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) { - console.log('error.code: ' + JSON.stringify(paramError.code) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -307,13 +303,12 @@ 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) - + ' error.message: ' + JSON.stringify(paramError.message)); + console.log('error.code: ${JSON.stringify(paramError.code)}, error.message: ${JSON.stringify(paramError.message)}'); } ``` @@ -345,10 +340,10 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import abilityManager from '@ohos.app.ability.abilityManager'; abilityManager.getTopAbility((err, data) => { - if (err.code !== 0) { - console.log("getTopAbility fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + 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)}'); } }); ``` @@ -381,8 +376,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)}'); }) ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md index 50feb82791f8992894641a296d6cb831fdc86680..89dc8c251534c355a0dca5d122b72d070a7ef460 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-abilityStage.md @@ -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'; } } ``` @@ -91,7 +91,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage'; class MyAbilityStage extends AbilityStage { onConfigurationUpdate(config) { - console.log('onConfigurationUpdate, language:' + config.language); + console.log('onConfigurationUpdate, language: ${config.language}'); } } ``` @@ -117,7 +117,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage'; class MyAbilityStage extends AbilityStage { onMemoryLevel(level) { - console.log('onMemoryLevel, level:' + JSON.stringify(level)); + console.log('onMemoryLevel, level: ${JSON.stringify(level)}'); } } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md index 840a395eac9e17558918dd7466aa9e0b178b1c4d..3943d78d7f01799de177b8297013c7c26b1c6c64 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-appManager.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-appManager.md @@ -40,10 +40,10 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; appManager.isRunningInStabilityTest((err, flag) => { - if (err.code !== 0) { - console.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('isRunningInStabilityTest fail, 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)}'); }); ``` @@ -146,10 +146,10 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; appManager.isRamConstrainedDevice((err, data) => { - if (err.code !== 0) { - console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('isRamConstrainedDevice fail, 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)}'); }); ``` @@ -216,17 +216,17 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; appManager.getAppMemorySize((err, data) => { - if (err.code !== 0) { - console.log("getAppMemorySize faile, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('getAppMemorySize fail, 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\>; +getRunningProcessInformation(): Promise\>; 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\> | 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\> | 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.getProcessRunningInformation9+ +## appManager.getRunningProcessInformation9+ -getProcessRunningInformation(callback: AsyncCallback\>): void; +getRunningProcessInformation(callback: AsyncCallback\>): 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\> | 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\> | 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) => { - if (err.code !== 0) { - console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err)); +appManager.getRunningProcessInformation((err, data) => { + if (err && err.code !== 0) { + console.log('getRunningProcessInformation fail, 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\): number; +on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\): 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` | 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; +off(type: 'applicationState', observerId: number, callback: AsyncCallback\): 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\ | 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} `); @@ -493,22 +489,22 @@ try { // 2. Deregister the application state observer. function unregisterApplicationStateObserverCallback(err) { - if (err.code !== 0) { - console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('unregisterApplicationStateObserverCallback fail, 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); + console.log('error: ${paramError.code}, ${paramError.message}'); } ``` ## appManager.off -off(type: "applicationState", observerId: number): Promise\; +off(type: 'applicationState', observerId: number): Promise\; 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,13 +570,13 @@ 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 fail, err: ${JSON.stringify(err)}'); }) } catch (paramError) { - console.log('error: ' + paramError.code + ', ' + paramError.message); + console.log('error: ${paramError.code}, ${paramError.message}'); } ``` @@ -616,16 +612,16 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error import appManager from '@ohos.app.ability.appManager'; function getForegroundApplicationsCallback(err, data) { - if (err.code !== 0) { - console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + 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}'); } ``` @@ -749,10 +745,10 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; let accountId = 0; function killProcessWithAccountCallback(err, data) { - if (err.code !== 0) { - console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + console.log('killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}'); } else { - console.log("killProcessWithAccountCallback success."); + console.log('killProcessWithAccountCallback success.'); } } appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); @@ -792,16 +788,16 @@ 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)); + if (err && err.code !== 0) { + 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}'); } ``` @@ -888,16 +884,16 @@ import appManager from '@ohos.app.ability.appManager'; let bundleName = 'bundleName'; function clearUpApplicationDataCallback(err, data) { - if (err) { - console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err)); + if (err && err.code !== 0) { + 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}'); } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md index e066ac119344842ffce617fd7934efa3712d895f..5a07867e6f5c28213e5cc48b07ef6a0958eb9426 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-appRecovery.md @@ -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}'); } ``` diff --git a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md index 3e95fbf541e7ed79834673c2ca97b1398bc73989..54200ed3e7e27043eb2798522a3fd1c991eca5a3 100644 --- a/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md +++ b/en/application-dev/reference/apis/js-apis-app-ability-startOptions.md @@ -18,7 +18,37 @@ 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.| +| [windowMode](js-apis-app-ability-abilityConstant.md#abilityconstantwindowmode) | number | No| Window mode.| | displayId | number | No| Display ID. The default value is **0**, indicating the current display.| + +**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}'); + } + ``` diff --git a/en/application-dev/reference/apis/js-apis-application-appManager.md b/en/application-dev/reference/apis/js-apis-application-appManager.md index a31f9c88969155dc1f0fc7717fd2aa6267ac3180..c1da72e6dbe619a208cc72ad7f34256862b21589 100644 --- a/en/application-dev/reference/apis/js-apis-application-appManager.md +++ b/en/application-dev/reference/apis/js-apis-application-appManager.md @@ -22,16 +22,16 @@ Checks whether this application is undergoing a stability test. This API uses an **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts appManager.isRunningInStabilityTest((err, flag) => { - console.log('error:' + JSON.stringfy(err)); - console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag)); + console.log('error: ${JSON.stringify(err)}'); + console.log('The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}'); }) ``` @@ -46,17 +46,17 @@ Checks whether this application is undergoing a stability test. This API uses a **Return value** - | Type| Description| - | -------- | -------- | - | Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts 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)}'); }); ``` @@ -71,17 +71,17 @@ Checks whether this application is running on a RAM constrained device. This API **Return value** - | Type| Description| - | -------- | -------- | - | Promise<boolean> | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| +| Type| Description| +| -------- | -------- | +| Promise<boolean> | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts 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)}'); }); ``` @@ -95,16 +95,16 @@ Checks whether this application is running on a RAM constrained device. This API **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<boolean> | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<boolean> | Yes| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| **Example** ```ts appManager.isRamConstrainedDevice((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data)); + console.log('error: ${JSON.stringify(err)}'); + console.log('The result of isRamConstrainedDevice is: ${JSON.stringify(data)}'); }) ``` @@ -118,17 +118,17 @@ Obtains the memory size of this application. This API uses a promise to return t **Return value** - | Type| Description| - | -------- | -------- | - | Promise<number> | Size of the application memory.| +| Type| Description| +| -------- | -------- | +| Promise<number> | Promise used to return the memory size, in MB.| **Example** ```ts 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)}'); }); ``` @@ -142,17 +142,17 @@ Obtains the memory size of this application. This API uses an asynchronous callb **Parameters** - | Name| Type| Mandatory| Description| - | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<number> | Yes| Size of the application memory.| +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| callback | AsyncCallback<number> | Yes| Callback used to return the memory size, in MB.| **Example** ```ts appManager.getAppMemorySize((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The size of app memory is:' + JSON.stringify(data)); - }) + console.log('error: ${JSON.stringify(err)}'); + console.log('The size of app memory is: ${JSON.stringify(data)}'); + }); ``` ## appManager.getProcessRunningInfos(deprecated) @@ -160,7 +160,7 @@ getProcessRunningInfos(): Promise\>; Obtains information about the running processes. This API uses a promise to return the result. -> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation9+](#appmanagergetprocessrunninginformation9) instead. +> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation9+](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation) instead. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -176,9 +176,9 @@ Obtains information about the running processes. This API uses a promise to retu ```ts appManager.getProcessRunningInfos().then((data) => { - console.log('The process running infos is:' + JSON.stringify(data)); + console.log('The process running infos is: ${JSON.stringify(data)}'); }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('error: ${JSON.stringify(error)}'); }); ``` @@ -188,7 +188,7 @@ getProcessRunningInfos(callback: AsyncCallback\>): vo Obtains information about the running processes. This API uses an asynchronous callback to return the result. -> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation9+](#appmanagergetprocessrunninginformation9-1) instead. +> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation9+](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation9) instead. **Required permissions**: ohos.permission.GET_RUNNING_INFO @@ -204,62 +204,11 @@ Obtains information about the running processes. This API uses an asynchronous c ```ts appManager.getProcessRunningInfos((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The process running infos is:' + JSON.stringify(data)); - }) - ``` - -## appManager.getProcessRunningInformation9+ - -getProcessRunningInformation(): Promise\>; - -Obtains information about the running processes. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.GET_RUNNING_INFO - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**Return value** - -| Type| Description| -| -------- | -------- | -| Promise\> | Obtains information about the running processes. This API uses a promise to return the result.| - -**Example** - - ```ts - appManager.getProcessRunningInformation().then((data) => { - console.log('The process running info is:' + JSON.stringify(data)); - }).catch((error) => { - console.log('error:' + JSON.stringify(error)); + console.log('error: ${JSON.stringify(err)}'); + console.log('The process running infos is: ${JSON.stringify(data)}'); }); ``` -## appManager.getProcessRunningInformation9+ - -getProcessRunningInformation(callback: AsyncCallback\>): void; - -Obtains information about the running processes. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.GET_RUNNING_INFO - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**Parameters** - -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| callback | AsyncCallback\> | Yes| Obtains information about the running processes. This API uses a promise to return the result.| - -**Example** - - ```ts - appManager.getProcessRunningInformation((err, data) => { - console.log('error:' + JSON.stringify(err)); - console.log('The process running info is:' + JSON.stringify(data)); - }) - ``` - ## appManager.registerApplicationStateObserver8+ registerApplicationStateObserver(observer: ApplicationStateObserver): number; @@ -281,7 +230,7 @@ Registers an observer to listen for the state changes of all applications. **Example** ```ts - var applicationStateObserver = { + let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log('------------ onForegroundApplicationChanged -----------', appStateData); }, @@ -297,7 +246,7 @@ Registers an observer to listen for the state changes of all applications. onProcessStateChanged(processData) { console.log('------------ onProcessStateChanged -----------', processData); } - } + }; const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver); console.log('-------- observerCode: ---------', observerCode); ``` @@ -324,7 +273,7 @@ Registers an observer to listen for the state changes of a specified application **Example** ```ts - var applicationStateObserver = { + let applicationStateObserver = { onForegroundApplicationChanged(appStateData) { console.log('------------ onForegroundApplicationChanged -----------', appStateData); }, @@ -340,8 +289,8 @@ Registers an observer to listen for the state changes of a specified application onProcessStateChanged(processData) { console.log('------------ onProcessStateChanged -----------', processData); } - } - var bundleNameList = ['bundleName1', 'bundleName2']; + }; + let bundleNameList = ['bundleName1', 'bundleName2']; const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver, bundleNameList); console.log('-------- observerCode: ---------', observerCode); ``` @@ -367,7 +316,7 @@ Deregisters the application state observer. This API uses an asynchronous callba **Example** ```ts - var observerId = 100; + let observerId = 100; function unregisterApplicationStateObserverCallback(err) { if (err) { @@ -404,7 +353,7 @@ Deregisters the application state observer. This API uses a promise to return th **Example** ```ts - var observerId = 100; + let observerId = 100; appManager.unregisterApplicationStateObserver(observerId) .then((data) => { @@ -412,7 +361,7 @@ Deregisters the application state observer. This API uses a promise to return th }) .catch((err) => { console.log('----------- unregisterApplicationStateObserver fail ----------', err); - }) + }); ``` ## appManager.getForegroundApplications8+ @@ -440,7 +389,7 @@ Obtains information about the applications that are running in the foreground. T if (err) { console.log('--------- getForegroundApplicationsCallback fail ---------', err); } else { - console.log('--------- getForegroundApplicationsCallback success ---------', data) + console.log('--------- getForegroundApplicationsCallback success ---------', data); } } appManager.getForegroundApplications(getForegroundApplicationsCallback); @@ -473,7 +422,7 @@ Obtains information about the applications that are running in the foreground. T }) .catch((err) => { console.log('--------- getForegroundApplications fail -------', err); - }) + }); ``` ## appManager.killProcessWithAccount8+ @@ -498,15 +447,15 @@ Kills a process by bundle name and account ID. This API uses a promise to return **Example** ```ts -var bundleName = 'bundleName'; -var accountId = 0; +let bundleName = 'bundleName'; +let accountId = 0; appManager.killProcessWithAccount(bundleName, accountId) .then((data) => { console.log('------------ killProcessWithAccount success ------------', data); }) .catch((err) => { console.log('------------ killProcessWithAccount fail ------------', err); - }) + }); ``` @@ -533,8 +482,8 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal **Example** ```ts -var bundleName = 'bundleName'; -var accountId = 0; +let bundleName = 'bundleName'; +let accountId = 0; function killProcessWithAccountCallback(err, data) { if (err) { console.log('------------- killProcessWithAccountCallback fail, err: --------------', err); @@ -567,7 +516,7 @@ Kills a process by bundle name. This API uses an asynchronous callback to return **Example** ```ts - var bundleName = 'bundleName'; + let bundleName = 'bundleName'; function killProcessesByBundleNameCallback(err, data) { if (err) { console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err); @@ -605,14 +554,14 @@ Kills a process by bundle name. This API uses a promise to return the result. **Example** ```ts - var bundleName = 'com.example.myapplication'; + let bundleName = 'com.example.myapplication'; appManager.killProcessesByBundleName(bundleName) .then((data) => { console.log('------------ killProcessesByBundleName success ------------', data); }) .catch((err) => { console.log('------------ killProcessesByBundleName fail ------------', err); - }) + }); ``` ## appManager.clearUpApplicationData8+ @@ -637,7 +586,7 @@ Clears application data by bundle name. This API uses an asynchronous callback t **Example** ```ts - var bundleName = 'bundleName'; + let bundleName = 'bundleName'; function clearUpApplicationDataCallback(err, data) { if (err) { console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err); @@ -675,40 +624,12 @@ Clears application data by bundle name. This API uses a promise to return the re **Example** ```ts - var bundleName = 'bundleName'; + let bundleName = 'bundleName'; appManager.clearUpApplicationData(bundleName) .then((data) => { console.log('------------ clearUpApplicationData success ------------', data); }) .catch((err) => { console.log('------------ clearUpApplicationData fail ------------', err); - }) + }); ``` - -## ApplicationState9+ - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**System API**: This is a system API and cannot be called by third-party applications. - -| Name | Value | Description | -| -------------------- | --- | --------------------------------- | -| STATE_CREATE | 1 | State indicating that the application is being created. | -| STATE_FOREGROUND | 2 | State indicating that the application is running in the foreground. | -| STATE_ACTIVE | 3 | State indicating that the application is active. | -| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. | -| STATE_DESTROY | 5 | State indicating that the application is destroyed. | - -## ProcessState9+ - -**System capability**: SystemCapability.Ability.AbilityRuntime.Core - -**System API**: This is a system API and cannot be called by third-party applications. - -| Name | Value | Description | -| -------------------- | --- | --------------------------------- | -| STATE_CREATE | 1 | State indicating that the process is being created. | -| STATE_FOREGROUND | 2 | State indicating that the process is running in the foreground. | -| STATE_ACTIVE | 3 | State indicating that the process is active. | -| STATE_BACKGROUND | 4 | State indicating that the process is running in the background. | -| STATE_DESTROY | 5 | State indicating that the process is destroyed. | diff --git a/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md b/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md index 271f2697803dde9d0b3f78c3bb661a03d925b95e..85b9503b48dc15a49c19cd74be00f071e93e3969 100644 --- a/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md +++ b/en/application-dev/reference/apis/js-apis-inner-application-errorObserver.md @@ -19,18 +19,17 @@ Called when an unhandled exception occurs in the JS runtime. **Example** ```ts -import errorManager from '@ohos.app.ability.errorManager' +import errorManager from '@ohos.app.ability.errorManager'; let observer = { - onUnhandledException(errorMsg) { - console.log('HXW onUnhandledException, errorMsg: ', errorMsg); - } -} + onUnhandledException(errorMsg) { + console.log('onUnhandledException, errorMsg: ', errorMsg); + } +}; try { - errorManager.on("error", observer); + errorManager.on('error', observer); } catch (error) { - console.log('registerErrorObserver' + ' failed, error.code: ' + JSON.stringify(error.code) + - ' error.message: ' + JSON.stringify(error.message)); + console.log('registerErrorObserver failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}'); } ```