提交 e2765fed 编写于 作者: D donglin 提交者: MacroYuan

doc optimize

Signed-off-by: Ndonglin <donglin9@huawei.com>
Change-Id: I29a634d8b0b31ede41d853660f31c84dbd9bc5ef
上级 28f2d6d5
......@@ -19,40 +19,66 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| launchReason | LaunchReason| 是 | 是 | 指示启动原因。 |
| lastExitReason | LastExitReason | 是 | 是 | 表示最后退出原因。 |
| launchReason | [LaunchReason](#abilityconstantlaunchreason)| 是 | 是 | 枚举类型,表示启动原因。 |
| lastExitReason | [LastExitReason](#abilityconstantlastexitreason) | 是 | 是 | 枚举类型,表示最后退出原因。 |
## AbilityConstant.LaunchReason
初次启动原因
Ability初次启动原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.launchReason的不同类型执行相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | 未知的状态。 |
| START_ABILITY | 1 | 启动能力。 |
| CALL | 2 | 呼叫。 |
| CONTINUATION | 3 | 继续。 |
| APP_RECOVERY | 4 | 状态恢复。 |
| UNKNOWN | 0 | 未知原因。 |
| START_ABILITY | 1 | 通过[startAbility](js-apis-ability-context.md#abilitycontextstartability)接口启动ability。 |
| CALL | 2 | 通过[startAbilityByCall](js-apis-ability-context.md#abilitycontextstartabilitybycall)接口启动ability。 |
| CONTINUATION | 3 | 跨端设备迁移启动ability。 |
| APP_RECOVERY | 4 | 设置应用恢复后,应用故障时自动恢复启动ability。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.launchReason == AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
}
}
}
```
## AbilityConstant.LastExitReason
上次退出原因
Ability上次退出原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onCreate(want, launchParam)](js-apis-app-ability-uiAbility.md#uiabilityoncreate)方法根据launchParam.lastExitReason的不同类型执行相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | 未知的状态。 |
| ABILITY_NOT_RESPONDING | 1 | 能力没有反应 |
| NORMAL | 2 | 正常的状态。 |
| UNKNOWN | 0 | 未知原因。 |
| ABILITY_NOT_RESPONDING | 1 | ability未响应。 |
| NORMAL | 2 | 正常退出。 |
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.lastExitReason == AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
}
}
}
```
## AbilityConstant.OnContinueResult
迁移结果
Ability迁移结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onContinue(wantParam)](js-apis-app-ability-uiAbility.md#uiabilityoncontinue)方法进完成相应的返回
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -62,9 +88,21 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| REJECT | 1 | 拒绝。 |
| MISMATCH | 2 | 不匹配。|
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onContinue(wantParam) {
return AbilityConstant.OnConinueResult.AGREE;
}
}
```
## AbilityConstant.WindowMode
启动Ability时的窗口模式。
启动Ability时的窗口模式,该类型为枚举,可配合startAbility使用指定启动Ability的窗口模式
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -76,36 +114,81 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| WINDOW_MODE_SPLIT_SECONDARY | 101 | 分屏多窗口次要模式。 |
| WINDOW_MODE_FLOATING | 102 | 自由悬浮形式窗口模式。 |
**示例:**
```ts
let want = {
bundleName: "com.test.example",
abilityName: "MainAbility"
};
let option = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
};
// 确保从上下文获取到context
this.context.startAbility(want, option).then(()={
console.log("Succeed to start ability.");
}).catch((error)=>{
console.log("Failed to start ability with error: " + JSON.stringify(error));
});
```
## AbilityConstant.MemoryLevel
内存级别。
内存级别,该类型为枚举,可配合[Ability](js-apis-app-ability-ability.md)[onMemoryLevel(level)](js-apis-app-ability-ability.md#abilityonmemorylevel)方法根据level执行不同内存级别的相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 |
| MEMORY_LEVEL_LOW | 1 | 内存占用低。 |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | 内存占用适中。 |
| MEMORY_LEVEL_LOW | 1 | 内存占用低。 |
| MEMORY_LEVEL_CRITICAL | 2 | 内存占用高。 |
**示例:**
```ts
import UIAbility form '@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.");
}
}
}
```
## AbilityConstant.OnSaveResult
保存应用数据的结果。
保存应用数据的结果,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate)方法完成相应的返回
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------------------------------------ |
| ALL_AGREE | 0 | 同意保存状态。 |
| ALL_AGREE | 0 | 总是同意保存状态。 |
| CONTINUATION_REJECT | 1 | 拒绝迁移保存状态。 |
| CONTINUATION_MISMATCH | 2 | 迁移不匹配。|
| RECOVERY_AGREE | 3 | 同意恢复保存状态。 |
| RECOVERY_REJECT | 4 | 拒绝恢复保存状态。|
| ALL_REJECT | 5 | 拒绝保存状态。|
| ALL_REJECT | 5 | 总是拒绝保存状态。|
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
}
```
## AbilityConstant.StateType
保存应用数据场景原因。
保存应用数据场景原因,该类型为枚举,可配合[Ability](js-apis-app-ability-uiAbility.md)[onSaveState(reason, wantParam)](js-apis-app-ability-uiAbility.md#uiabilityonsavestate)方法根据reason的不同类型执行相应操作
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -113,3 +196,18 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
| ----------------------------- | ---- | ------------------------------------------------------------ |
| CONTINUATION | 0 | 迁移保存状态。 |
| APP_RECOVERY | 1 | 应用恢复保存状态。 |
**示例:**
```ts
import UIAbility form '@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.");
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
}
```
\ No newline at end of file
# @ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)
AbilityDelegatorRegistry模块提供用于存储已注册的AbilityDelegator和AbilityDelegatorArgs对象的全局寄存器的能力,包括获取应用程序的AbilityDelegator对象、获取单元测试参数AbilityDelegatorArgs对象
AbilityDelegatorRegistry[测试框架](../../ability-deprecated/ability-delegator.md)模块,该模块用于获取[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象,其中[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)对象提供添加用于监视指定ability的生命周期状态更改的AbilityMonitor对象的能力,[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象提供获取当前测试参数的能力
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在测试框架中使用。
## 导入模块
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
```
## AbilityLifecycleState
Ability生命周期状态。
Ability生命周期状态,该类型为枚举,可配合[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)[getAbilityState(ability)](js-apis-inner-application-abilityDelegator.md#getabilitystate9)方法返回不同ability生命周期
**系统能力** :以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 值 | 说明 |
| ------------- | ---- | --------------------------- |
| UNINITIALIZED | 0 | 表示无效状态。 |
| UNINITIALIZED | 0 | 表示Ability处于无效状态。 |
| CREATE | 1 | 表示Ability处于已创建状态。 |
| FOREGROUND | 2 | 表示Ability处于前台状态。 |
| BACKGROUND | 3 | 表示Ability处于后台状态。 |
......@@ -28,9 +29,9 @@ Ability生命周期状态。
## AbilityDelegatorRegistry.getAbilityDelegator
getAbilityDelegator(): AbilityDelegator
getAbilityDelegator(): [AbilityDelegator](js-apis-inner-application-abilityDelegator.md)
获取应用程序的AbilityDelegator对象
获取应用程序的[AbilityDelegator](js-apis-inner-application-abilityDelegator.md)对象,该对象能够使用调度测试框架的相关功能。
**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
......@@ -43,15 +44,29 @@ getAbilityDelegator(): AbilityDelegator
**示例:**
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.ohos.example",
abilityName: "MainAbility"
}
abilityDelegator.startAbility(want, (err)=>{
if (err.code != 0) {
console.log("Success start ability.");
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
}
})
```
## AbilityDelegatorRegistry.getArguments
getArguments(): AbilityDelegatorArgs
getArguments(): [AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)
获取单元测试参数AbilityDelegatorArgs对象
获取单元测试参数[AbilityDelegatorArgs](js-apis-inner-application-abilityDelegatorArgs.md)对象。
**系统能力:** SystemCapability.Ability.AbilityRuntime.Core
......@@ -64,8 +79,11 @@ getArguments(): AbilityDelegatorArgs
**示例:**
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var 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);
```
# @ohos.app.ability.abilityLifecycleCallback (AbilityLifecycleCallback)
AbilityLifecycleCallback模块提供应用上下文ApplicationContext的生命周期监听方法的回调类的能力,包括onAbilityCreate、onWindowStageCreate、onWindowStageDestroy等方法。
AbilityLifecycleCallback模块提供应用上下文[ApplicationContext](js-apis-inner-application-applicationContext.md)的生命周期发生变化时触发相应回调的能力,包括[onAbilityCreate](#abilitylifecyclecallbackonabilitycreate)[onWindowStageCreate](#abilitylifecyclecallbackonwindowstagecreate)[onWindowStageActive](#abilitylifecyclecallbackonwindowstageactive)[onWindowStageInactive](#abilitylifecyclecallbackonwindowstageinactive)[onWindowStageDestroy](#abilitylifecyclecallbackonwindowstagedestroy)[onAbilityDestroy](#abilitylifecyclecallbackonabilitydestroy)[onAbilityForeground](#abilitylifecyclecallbackonabilityforeground)[onAbilityBackground](#abilitylifecyclecallbackonabilitybackground)[onAbilityContinue](#abilitylifecyclecallbackonabilitycontinue)方法。
> **说明:**
>
......@@ -17,7 +17,7 @@ import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback
## AbilityLifecycleCallback.onAbilityCreate
onAbilityCreate(ability: UIAbility): void;
onAbilityCreate(ability: [UIAbility](js-apis-app-ability-uiAbility.md)): void;
注册监听应用上下文的生命周期后,在ability创建时触发回调。
......@@ -27,12 +27,12 @@ onAbilityCreate(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onWindowStageCreate
onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
onWindowStageCreate(ability: [UIAbility](js-apis-app-ability-uiAbility.md), windowStage: [window.WindowStage](js-apis-window.md#windowstage9)): void;
注册监听应用上下文的生命周期后,在windowStage创建时触发回调。
......@@ -42,13 +42,13 @@ onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
## AbilityLifecycleCallback.onWindowStageActive
onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
onWindowStageActive(ability: [UIAbility](js-apis-app-ability-uiAbility.md), windowStage: [window.WindowStage](js-apis-window.md#windowstage9)): void;
注册监听应用上下文的生命周期后,在windowStage获焦时触发回调。
......@@ -58,13 +58,13 @@ onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
## AbilityLifecycleCallback.onWindowStageInactive
onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void;
onWindowStageInactive(ability: [UIAbility](js-apis-app-ability-uiAbility.md), windowStage: [window.WindowStage](js-apis-window.md#windowstage9)): void;
注册监听应用上下文的生命周期后,在windowStage失焦时触发回调。
......@@ -74,13 +74,13 @@ onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
## AbilityLifecycleCallback.onWindowStageDestroy
onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
onWindowStageDestroy(ability: [UIAbility](js-apis-app-ability-uiAbility.md), windowStage: [window.WindowStage](js-apis-window.md#windowstage9)): void;
注册监听应用上下文的生命周期后,在windowStage销毁时触发回调。
......@@ -90,13 +90,13 @@ onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
## AbilityLifecycleCallback.onAbilityDestroy
onAbilityDestroy(ability: UIAbility): void;
onAbilityDestroy(ability: [UIAbility](js-apis-app-ability-uiAbility.md)): void;
注册监听应用上下文的生命周期后,在ability销毁时触发回调。
......@@ -106,12 +106,12 @@ onAbilityDestroy(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityForeground
onAbilityForeground(ability: UIAbility): void;
onAbilityForeground(ability: [UIAbility](js-apis-app-ability-uiAbility.md)): void;
注册监听应用上下文的生命周期后,在ability的状态从后台转到前台时触发回调。
......@@ -121,12 +121,12 @@ onAbilityForeground(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityBackground
onAbilityBackground(ability: UIAbility): void;
onAbilityBackground(ability: [UIAbility](js-apis-app-ability-uiAbility.md)): void;
注册监听应用上下文的生命周期后,在ability的状态从前台转到后台时触发回调。
......@@ -136,12 +136,12 @@ onAbilityBackground(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
## AbilityLifecycleCallback.onAbilityContinue
onAbilityContinue(ability: UIAbility): void;
onAbilityContinue(ability: [UIAbility](js-apis-app-ability-uiAbility.md)): void;
注册监听应用上下文的生命周期后,在ability迁移时触发回调。
......@@ -151,61 +151,63 @@ onAbilityContinue(ability: UIAbility): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md#Ability) | 是 | 当前Ability对象 |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
```ts
import UIAbility from "@ohos.app.ability.UIAbility";
export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageActive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy ability:" + JSON.stringify(ability));
console.log("AbilityLifecycleCallback onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy ability:" + JSON.stringify(ability));
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground ability:" + JSON.stringify(ability));
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground ability:" + JSON.stringify(ability));
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue ability:" + JSON.stringify(ability));
}
}
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
let lifecycleid = applicationContext.on("abilityLifecycle", AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.off("abilityLifecycle", lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
```
\ No newline at end of file
// 声明ability生命周期回调
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
}
}
export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
globalThis.lifecycleid = applicationContext.on("abilityLifecycle", abilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
// 3.通过applicationContext注销监听应用内生命周期
applicationContext.off("abilityLifecycle", globalThis.lifecycleid, (error) => {
if (error != 0) {
console,log("unregisterAbilityLifecycleCallback failed, error: " + JSON.stringify(error));
} else {
console.log("unregisterAbilityLifecycleCallback success.");
}
});
}
}
```
\ No newline at end of file
# @ohos.app.ability.abilityManager (AbilityManager)
AbilityManager模块提供对Ability相关信息和状态信息进行获取、新增、修改等能力。
AbilityManager模块提供获取、新增、修改Ability相关信息和状态信息进行的能力。
> **说明:**
>
......@@ -15,7 +15,7 @@ import abilityManager from '@ohos.app.ability.abilityManager'
## AbilityState
Ability的状态信息
Ability的状态,该类型为枚举,可配合[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)返回Abiltiy的状态
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -23,17 +23,17 @@ Ability的状态信息。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| INITIAL | 0 | 表示ability为initial状态。|
| FOREGROUND | 9 | 表示ability为foreground状态。 |
| BACKGROUND | 10 | 表示ability为background状态。 |
| FOREGROUNDING | 11 | 表示ability为foregrounding状态。 |
| BACKGROUNDING | 12 | 表示ability为backgrounding状态。 |
| INITIAL | 0 | 表示ability为初始化状态。|
| FOREGROUND | 9 | 表示ability为前台状态。 |
| BACKGROUND | 10 | 表示ability为后台状态。 |
| FOREGROUNDING | 11 | 表示ability为前台调度中状态。 |
| BACKGROUNDING | 12 | 表示ability为后台调度中状态。 |
## updateConfiguration
updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
updateConfiguration(config: [Configuration](js-apis-app-ability-configuration.md), callback: AsyncCallback\<void>): void
通过修改配置来更新配置(callback形式)。
通过传入修改的配置项来更新配置(callback形式)。
**需要权限**: ohos.permission.UPDATE_CONFIGURATION
......@@ -43,29 +43,38 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项。 |
| callback | AsyncCallback\<void> | 是 | 被指定的回调方法。 |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项,仅需配置需要更新的项。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例**
```ts
var config = {
language: 'chinese'
language: 'chinese',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
try {
abilityManager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
abilityManager.updateConfiguration(config, (err) => {
if (err.code != 0) {
console.log("updateConfiguration fail, err: " + JSON.stringify(err));
} else {
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));
}
```
## updateConfiguration
updateConfiguration(config: Configuration): Promise\<void>
updateConfiguration(config: [Configuration](js-apis-app-ability-configuration.md)): Promise\<void>
通过修改配置来更新配置(Promise形式)。
......@@ -77,36 +86,41 @@ updateConfiguration(config: Configuration): Promise\<void>
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项。 |
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项,仅需配置需要更新的项。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<void> | 返回执行结果。 |
| Promise\<void> | 以Promise方式返回接口运行结果息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
var config = {
language: 'chinese'
language: 'chinese',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
try {
abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
})
abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success.');
}).catch((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));
}
```
## getAbilityRunningInfos
getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
getAbilityRunningInfos(callback: AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>>): void
获取Ability运行相关信息(callback形式)。
......@@ -118,24 +132,28 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): vo
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<AbilityRunningInfo>> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
try {
abilityManager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
abilityManager.getAbilityRunningInfos((err,data) => {
if (err.code != 0) {
console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
} else {
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));
}
```
## getAbilityRunningInfos
getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
getAbilityRunningInfos(): Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>>
获取Ability运行相关信息(Promise形式)。
......@@ -147,26 +165,26 @@ getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<Array\<AbilityRunningInfo>> | 返回执行结果。 |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**示例**
```ts
try {
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
});
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
}).catch((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));
}
```
## getExtensionRunningInfos
getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<ExtensionRunningInfo>>): void
getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>>): void
获取关于运行扩展能力的信息(callback形式)。
......@@ -179,7 +197,7 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<Ext
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | 是 | 获取消息数量的最大限制。 |
| callback | AsyncCallback\<Array\<AbilityRunningInfo>> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**示例**
......@@ -187,18 +205,22 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<Ext
var upperLimit = 0;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
if (err.code != 0) {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
} else {
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));
}
```
## getExtensionRunningInfos
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
getExtensionRunningInfos(upperLimit: number): Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>>
获取关于运行扩展能力的信息(Promise形式)。
......@@ -216,7 +238,7 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<Array\<AbilityRunningInfo>> | 返回执行结果。 |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**示例**
......@@ -224,20 +246,20 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
var upperLimit = 0;
try {
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err);
})
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
}).catch((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));
}
```
## getTopAbility<sup>9+</sup>
getTopAbility(callback: AsyncCallback\<ElementName>): void;
getTopAbility(callback: AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)>): void;
获取窗口焦点的ability接口(callback形式)。
......@@ -247,19 +269,23 @@ getTopAbility(callback: AsyncCallback\<ElementName>): void;
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<ElementName> | 是 | 被指定的回调方法。 |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 以回调方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**示例**
```ts
abilityManager.getTopAbility((err,data) => {
console.log("getTopAbility err: " + err + " data: " + JSON.stringify(data));
if (err.code != 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
}
});
```
## getTopAbility
getTopAbility(): Promise\<ElementName>;
getTopAbility(): Promise\<[ElementName](js-apis-bundleManager-elementName.md)>;
获取窗口焦点的ability接口(Promise形式)。
......@@ -269,14 +295,14 @@ getTopAbility(): Promise\<ElementName>;
| 类型 | 说明 |
| ---------------------------------------- | ------- |
| Promise\<ElementName>| 返回执行结果。 |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| 以Promise方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**示例**
```ts
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility data: " + JSON.stringify(data));
console.log("getTopAbility success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility err: " + err);
console.log("getTopAbility fail, err: " + JSON.stringify(err));
})
```
\ No newline at end of file
......@@ -25,18 +25,18 @@ onCreate(): void
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called")
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
}
}
```
## AbilityStage.onAcceptWant
onAcceptWant(want: Want): string;
onAcceptWant(want: [Want](js-apis-app-ability-want.md)): string;
启动一个specified ability时触发的事件。
......@@ -56,19 +56,19 @@ onAcceptWant(want: Want): string;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
}
}
```
## AbilityStage.onConfigurationUpdate
onConfigurationUpdate(newConfig: Configuration): void;
onConfigurationUpdate(newConfig: [Configuration](js-apis-app-ability-configuration.md)): void;
环境变化通知接口,发生全局配置变更时回调。
......@@ -82,17 +82,17 @@ onConfigurationUpdate(newConfig: Configuration): void;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
}
}
```
```ts
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
}
}
```
## AbilityStage.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
onMemoryLevel(level: [AbilityConstant.MemoryLevel](js-apis-app-ability-abilityConstant.md#abilityconstantmemorylevel)): void;
当系统已决定调整内存时调用。例如,当该功能在后台运行时,没有足够的内存来运行尽可能多的后台进程时可以使用。
......@@ -106,22 +106,22 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:**
```ts
class MyAbilityStage extends AbilityStage {
```ts
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
}
```
## AbilityStage.context
context: AbilityStageContext;
context: [AbilityStageContext](js-apis-inner-application-abilityStageContext.md);
指示有关上下文的配置信息
指示AbilityStage的上下文,
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 属性名 | 类型 | 说明 |
| ----------- | --------------------------- | ------------------------------------------------------------ |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | 在启动能力阶段进行初始化时回调。 |
| context | [AbilityStageContext](js-apis-inner-application-abilityStageContext.md) | 在Ability启动阶段进行初始化时回调,获取到该Ability的context值。 |
......@@ -20,20 +20,23 @@ static isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
**返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回当前是否处于稳定性测试场景。 |
| 类型| 说明 |
| -------- | -------- |
|AsyncCallback&lt;boolean&gt; |以回调方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```ts
appManager.isRunningInStabilityTest((err, flag) => {
console.log('error:' + JSON.stringify(err));
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
})
```
```ts
appManager.isRunningInStabilityTest((err, flag) => {
if (err.code != 0) {
conseole.log("isRunningInStabilityTest faile, err: " + JSON.stringify(err));
} else {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
}
})
```
## appManager.isRunningInStabilityTest
......@@ -48,17 +51,17 @@ static isRunningInStabilityTest(): Promise&lt;boolean&gt;
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 返回当前是否处于稳定性测试场景。 |
| Promise&lt;boolean&gt; | 以Promise方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
**示例:**
```ts
appManager.isRunningInStabilityTest().then((flag) => {
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}).catch((error) => {
console.log('error:' + JSON.stringify(error));
});
```
```ts
appManager.isRunningInStabilityTest().then((flag) => {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
});
```
## appManager.isRamConstrainedDevice
......@@ -73,17 +76,17 @@ isRamConstrainedDevice(): Promise\<boolean>;
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 是否为ram受限设备。 |
| Promise&lt;boolean&gt; | 以Promise方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```ts
appManager.isRamConstrainedDevice().then((data) => {
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}).catch((error) => {
console.log('error:' + JSON.stringify(error));
});
```
```ts
appManager.isRamConstrainedDevice().then((data) => {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
});
```
## appManager.isRamConstrainedDevice
......@@ -93,20 +96,23 @@ isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
**返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 返回当前是否是ram受限设备。 |
| 类型 | 说明 |
| -------- | -------- |
| AsyncCallback&lt;boolean&gt; |以回调方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
**示例:**
```ts
appManager.isRamConstrainedDevice((err, data) => {
console.log('error:' + JSON.stringify(err));
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
})
```
```ts
appManager.isRamConstrainedDevice((err, data) => {
if (err.code != 0) {
console.log("isRamConstrainedDevice faile, err: " + JSON.stringify(err));
} else {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
}
})
```
## appManager.getAppMemorySize
......@@ -120,17 +126,17 @@ getAppMemorySize(): Promise\<number>;
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;number&gt; | 应用程序内存大小。 |
| Promise&lt;number&gt; | 以Promise方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
appManager.getAppMemorySize().then((data) => {
console.log('The size of app memory is:' + JSON.stringify(data));
}).catch((error) => {
console.log('error:' + JSON.stringify(error));
});
```
```ts
appManager.getAppMemorySize().then((data) => {
console.log("The size of app memory is:" + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
});
```
## appManager.getAppMemorySize
......@@ -140,24 +146,27 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
**返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 应用程序内存大小。 |
| 类型 | 说明 |
| -------- | -------- |
|AsyncCallback&lt;number&gt; |以回调方式返回接口运行结果及应用程序内存大小,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
appManager.getAppMemorySize((err, data) => {
console.log('error:' + JSON.stringify(err));
console.log('The size of app memory is:' + JSON.stringify(data));
})
```
```ts
appManager.getAppMemorySize((err, data) => {
if (err.code != 0) {
console.log("getAppMemorySize faile, err: " + JSON.stringify(err));
} else {
console.log("The size of app memory is:" + JSON.stringify(data));
}
})
```
## appManager.getProcessRunningInformation<sup>9+</sup>
getProcessRunningInformation(): Promise\<Array\<ProcessRunningInformation>>;
getProcessRunningInformation(): Promise\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>>;
获取有关运行进程的信息。
......@@ -171,21 +180,21 @@ getProcessRunningInformation(): Promise\<Array\<ProcessRunningInformation>>;
| 类型 | 说明 |
| -------- | -------- |
| Promise\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | 获取有关运行进程的信息。 |
| Promise\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | 以Promise方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
appManager.getProcessRunningInformation().then((data) => {
console.log('The process running infomation is:' + JSON.stringify(data));
}).catch((error) => {
console.log('error:' + JSON.stringify(error));
});
```
```ts
appManager.getProcessRunningInformation().then((data) => {
console.log("The process running information is:" + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
});
```
## appManager.getProcessRunningInformation<sup>9+</sup>
getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInformation>>): void;
getProcessRunningInformation(callback: AsyncCallback\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>>): void;
获取有关运行进程的信息。
......@@ -195,24 +204,27 @@ getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInfor
**系统API**: 此接口为系统接口,三方应用不支持调用。
**参数:**
**返回值:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | 是 | 获取有关运行进程的信息。 |
| 类型 | 说明 |
| -------- | -------- |
|AsyncCallback\<Array\<[ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)>> | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
appManager.getProcessRunningInformation((err, data) => {
console.log('error :' + JSON.stringify(err));
console.log('The process running information is:' + JSON.stringify(data));
})
```
```ts
appManager.getProcessRunningInformation((err, data) => {
if (err.code != 0) {
console.log("getProcessRunningInformation faile, err: " + JSON.stringify(err));
} else {
console.log("The process running information is:" + JSON.stringify(data));
}
})
```
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver): number;
on(type: "applicationState", observer: [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md)): number;
注册全部应用程序状态观测器。
......@@ -226,41 +238,46 @@ on(type: "applicationState", observer: ApplicationStateObserver): number;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 返回观察者的数字代码。 |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口注销观测器。|
**示例:**
```js
var applicationStateObserver = {
```js
var applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
console.log('------------ onForegroundApplicationChanged -----------' + JSON.stringify(appStateData));
},
onAbilityStateChanged(abilityStateData) {
console.log('------------ onAbilityStateChanged -----------', abilityStateData);
console.log('------------ onAbilityStateChanged -----------' + JSON.stringify(abilityStateData));
},
onProcessCreated(processData) {
console.log('------------ onProcessCreated -----------', processData);
console.log('------------ onProcessCreated -----------' + JSON.stringify(processData));
},
onProcessDied(processData) {
console.log('------------ onProcessDied -----------', processData);
console.log('------------ onProcessDied -----------' + JSON.stringify(processData));
},
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
console.log('------------ onProcessStateChanged -----------' + JSON.stringify(processData));
}
}
try {
}
try {
const observerCode = appManager.on(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
} catch (paramError) {
console.log('-------- observerCode: ---------' + observerCode);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
}
```
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
on(type: "applicationState", observer: [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md), bundleNameList: Array\<string>): number;
注册指定应用程序状态观测器。
......@@ -274,39 +291,45 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 返回观察者的数字代码。 |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
| bundleNameList | Array<string> | 是 | 表示需要注册监听的bundleName数组。最大值128。 |
**返回值:**
| 类型 | 说明 |
| --- | --- |
| number | 已注册观测器的数字代码,可用于off接口注销观测器。|
**示例:**
```js
var applicationStateObserver = {
```js
var applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
console.log('------------ onForegroundApplicationChanged -----------' + JSON.stringify(appStateData));
},
onAbilityStateChanged(abilityStateData) {
console.log('------------ onAbilityStateChanged -----------', abilityStateData);
console.log('------------ onAbilityStateChanged -----------' + JSON.stringify(abilityStateData));
},
onProcessCreated(processData) {
console.log('------------ onProcessCreated -----------', processData);
console.log('------------ onProcessCreated -----------' + JSON.stringify(processData));
},
onProcessDied(processData) {
console.log('------------ onProcessDied -----------', processData);
console.log('------------ onProcessDied -----------' + JSON.stringify(processData));
},
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
console.log('------------ onProcessStateChanged -----------' + JSON.stringify(processData));
}
}
var bundleNameList = ['bundleName1', 'bundleName2'];
try {
}
var bundleNameList = ['bundleName1', 'bundleName2'];
try {
const observerCode = appManager.on("applicationState", applicationStateObserver, bundleNameList);
console.log('-------- observerCode: ---------', observerCode);
} catch (paramError) {
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
}
```
```
## appManager.off
off(type: "applicationState", observerId: number, callback: AsyncCallback\<void>): void;
......@@ -323,26 +346,28 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型 |
| observerId | number | 是 | 表示观察者的编号代码。 |
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```js
var observerId = 100;
```ts
var observerId = 100;
function unregisterApplicationStateObserverCallback(err) {
if (err) {
console.log('------------ unregisterApplicationStateObserverCallback ------------', err);
}
}
try {
appManager.off(observerId, unregisterApplicationStateObserverCallback);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
function unregisterApplicationStateObserverCallback(err) {
if (err.code != 0) {
console.log("unregisterApplicationStateObserverCallback faile, err: " + JSON.stringify(err));
} else {
console.log("unregisterApplicationStateObserverCallback success.");
}
```
}
try {
appManager.off(observerId, unregisterApplicationStateObserverCallback);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## appManager.off
......@@ -360,36 +385,34 @@ off(type: "applicationState", observerId: number): Promise\<void>;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型 |
| observerId | number | 是 | 表示观察者的编号代码。 |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise\<void> | 返回执行结果。 |
| Promise\<void> | 以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```js
var observerId = 100;
```ts
var observerId = 100;
try {
appManager.off(observerId)
.then((data) => {
console.log('----------- unregisterApplicationStateObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterApplicationStateObserver fail ----------', err);
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
try {
appManager.off(observerId).then((data) => {
console.log("unregisterApplicationStateObserver success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("unregisterApplicationStateObserver faile, err: " + JSON.stringify(err));
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## appManager.getForegroundApplications
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
getForegroundApplications(callback: AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>>): void;
获取前台进程的应用程序。
......@@ -403,67 +426,28 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<AppStateData>> | 是 | 表示应用的状态数据。 |
| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 是 | 以回调方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理。 |
**示例:**
```js
function getForegroundApplicationsCallback(err, data) {
if (err) {
console.log('--------- getForegroundApplicationsCallback fail ---------', err.code + ': ' + err.message);
```ts
function getForegroundApplicationsCallback(err, data) {
if (err.code != 0) {
console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
} else {
console.log('--------- getForegroundApplicationsCallback success ---------', data)
console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
}
}
try {
}
try {
appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
unregisterApplicationStateObserver(observerId: number): Promise\<void>;
取消注册应用程序状态观测器。
**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**:该接口为系统接口,三方应用不支持调用。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| observerId | number | 是 | 表示观察者的编号代码。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise\<void> | 返回执行结果。 |
**示例:**
```ts
var observerId = 100;
try {
appManager.unregisterApplicationStateObserver(observerId)
.then((data) => {
console.log('----------- unregisterApplicationStateObserver success ----------', data);
})
.catch((err) => {
console.log('----------- unregisterApplicationStateObserver fail ----------', err);
})
} catch (paramError) {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## appManager.getForegroundApplications
getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
getForegroundApplications(callback: AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>>): void;
获取前台进程的应用程序。
......@@ -477,28 +461,28 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<AppStateData>> | 是 | 表示应用的状态数据。 |
| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 是 | 以Promise方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
function getForegroundApplicationsCallback(err, data) {
if (err) {
console.log('--------- getForegroundApplicationsCallback fail ---------', err);
```ts
function getForegroundApplicationsCallback(err, data) {
if (err.code != 0) {
console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
} else {
console.log('--------- getForegroundApplicationsCallback success ---------', data)
console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
}
}
try {
}
try {
appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## appManager.getForegroundApplications
getForegroundApplications(): Promise\<Array\<AppStateData>>;
getForegroundApplications(): Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>>;
获取前台进程的应用程序。
......@@ -512,19 +496,17 @@ getForegroundApplications(): Promise\<Array\<AppStateData>>;
| 类型 | 说明 |
| -------- | -------- |
| Promise\<Array\<ProcessRunningInfo>> | 返回进程运行信息的数组。 |
| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 返回前台进程应用程序的数组。 |
**示例:**
```ts
appManager.getForegroundApplications()
.then((data) => {
console.log('--------- getForegroundApplications success -------', data);
})
.catch((err) => {
console.log('--------- getForegroundApplications fail -------', err);
})
```
```ts
appManager.getForegroundApplications().then((data) => {
console.log("getForegroundApplications success, data: " + JSON.stringify(data));
}).catch((err) => {
console.log("getForegroundApplications fail, err: " + JSON.stringify(err));
})
```
## appManager.killProcessWithAccount
......@@ -551,15 +533,13 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
var bundleName = 'bundleName';
var accountId = 0;
try {
appManager.killProcessWithAccount(bundleName, accountId)
.then((data) => {
console.log('------------ killProcessWithAccount success ------------', data);
})
.catch((err) => {
console.log('------------ killProcessWithAccount fail ------------', err);
})
appManager.killProcessWithAccount(bundleName, accountId).then(() => {
console.log("killProcessWithAccount success");
}).catch((err) => {
console.log("killProcessWithAccount fail, err: " + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
......@@ -582,7 +562,7 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用包名。 |
| accountId | number | 是 | 系统帐号的帐号ID,详情参考[getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess)。 |
| callback | AsyncCallback\<void\> | 是 | 切断account进程的回调函数。 |
| callback | AsyncCallback\<void\> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
......@@ -590,11 +570,11 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
var bundleName = 'bundleName';
var accountId = 0;
function killProcessWithAccountCallback(err, data) {
if (err) {
console.log('------------- killProcessWithAccountCallback fail, err: --------------', err);
} else {
console.log('------------- killProcessWithAccountCallback success, data: --------------', data);
}
if (err.code != 0) {
console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err));
} else {
console.log("killProcessWithAccountCallback success.");
}
}
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
```
......@@ -616,25 +596,25 @@ killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 表示包名。 |
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
var bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err) {
console.log('------------- killProcessesByBundleNameCallback fail, err: --------------', err);
```ts
var bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err.code != 0) {
console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err));
} else {
console.log('------------- killProcessesByBundleNameCallback success, data: --------------', data);
console.log("killProcessesByBundleNameCallback success.");
}
}
try {
}
try {
appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
} catch (paramError) {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## appManager.killProcessesByBundleName
......@@ -652,7 +632,7 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 表示包名。 |
| bundleName | string | 是 | 表示应用包名。 |
**返回值:**
......@@ -662,20 +642,18 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
**示例:**
```ts
var bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName)
.then((data) => {
console.log('------------ killProcessesByBundleName success ------------', data);
})
.catch((err) => {
console.log('------------ killProcessesByBundleName fail ------------', err);
```ts
var bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName).then((data) => {
console.log("killProcessesByBundleName success.");
}).catch((err) => {
console.log("killProcessesByBundleName fail, err: " + JSON.stringify(err));
})
} catch (paramError) {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## appManager.clearUpApplicationData
......@@ -694,25 +672,25 @@ clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 表示包名。 |
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
var bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
```ts
var bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err) {
console.log('------------- clearUpApplicationDataCallback fail, err: --------------', err);
console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err));
} else {
console.log('------------- clearUpApplicationDataCallback success, data: --------------', data);
console.log("clearUpApplicationDataCallback success.");
}
}
try {
}
try {
appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
} catch (paramError) {
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## appManager.clearUpApplicationData
......@@ -736,27 +714,27 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
| 类型 | 说明 |
| -------- | -------- |
| Promise\<void> | 返回执行结果。 |
| Promise\<void> | 以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**示例:**
```ts
var bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName)
.then((data) => {
console.log('------------ clearUpApplicationData success ------------', data);
})
.catch((err) => {
console.log('------------ clearUpApplicationData fail ------------', err);
})
} catch (paramError) {
```ts
var bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName).then((data) => {
console.log("clearUpApplicationData success.");
}).catch((err) => {
console.log("clearUpApplicationData fail, err: " + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
}
```
## ApplicationState
应用状态,该类型为枚举,可配合[AbilityStateData](js-apis-inner-application-appStateData.md)返回相应的应用状态。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
......@@ -771,6 +749,8 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
## ProcessState
进程状态,该类型为枚举,可配合[ProcessData](js-apis-inner-application-processData.md)返回相应的进程状态。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**系统API**: 此接口为系统接口,三方应用不支持调用。
......
......@@ -14,7 +14,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.RestartFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口重启选项参数
应用重启标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口重启选项参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -28,7 +28,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.SaveOccasionFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存时机选项参数
保存条件标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存时的选项参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -39,7 +39,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.SaveModeFlag
[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存方式的参数
状态保存标志,[enableAppRecovery](#apprecoveryenableapprecovery)接口状态保存方式的参数,该类型为枚举
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -50,7 +50,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'
## appRecovery.enableAppRecovery
enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMode?: SaveModeFlag) : void;
enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion?: [SaveOccasionFlag](#apprecoverysaveoccasionflag), saveMode?: [SaveModeFlag](#apprecoverysavemodeflag)) : void;
使能应用恢复功能,参数按顺序填入。
......@@ -60,9 +60,9 @@ enableAppRecovery(restart?: RestartFlag, saveOccasion?: SaveOccasionFlag, saveMo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| restart | [RestartFlag](#apprecoveryrestartflag) | 否 | 发生对应故障时是否重启,默认为不重启。 |
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | 否 | 状态保存时机,默认为故障时保存。 |
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | 否 | 状态保存方式, 默认为文件缓存。 |
| restart | [RestartFlag](#apprecoveryrestartflag) | 否 | 枚举类型,发生对应故障时是否重启,默认为不重启。 |
| saveOccasion | [SaveOccasionFlag](#apprecoverysaveoccasionflag) | 否 | 枚举类型,状态保存时机,默认为故障时保存。 |
| saveMode | [SaveModeFlag](#apprecoverysavemodeflag) | 否 | 枚举类型,状态保存方式, 默认为文件缓存。 |
**示例:**
......@@ -94,7 +94,6 @@ var observer = {
appRecovery.restartApp();
}
}
```
## appRecovery.saveAppState
......@@ -109,7 +108,7 @@ saveAppState(): boolean;
| 类型 | 说明 |
| -------- | -------- |
| boolean | 保存成功与否。 |
| boolean | 保存成功与否。true:保存成功,false:保存失败。 |
**示例:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册