未验证 提交 6b5cc367 编写于 作者: O openharmony_ci 提交者: Gitee

!13023 【元能力】abilityManager、appManager错误码

Merge pull request !13023 from donglin/master
......@@ -59,7 +59,8 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -114,7 +115,8 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback<void&
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -177,7 +179,8 @@ startAbility(want: Want, options?: StartOptions): Promise<void>;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -234,7 +237,8 @@ startAbilityForResult(want: Want, callback: AsyncCallback<AbilityResult>):
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -290,7 +294,8 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -356,7 +361,8 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise<AbilityRes
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -417,7 +423,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -480,7 +487,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -551,7 +559,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -606,7 +615,8 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -656,7 +666,8 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -710,7 +721,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -764,7 +776,8 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -815,7 +828,8 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -871,7 +885,8 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -931,7 +946,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -991,7 +1007,8 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1046,7 +1063,8 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1083,7 +1101,8 @@ terminateSelf(): Promise&lt;void&gt;;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1119,7 +1138,8 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1180,7 +1200,8 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1243,7 +1264,8 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1301,7 +1323,8 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1353,7 +1376,8 @@ disconnectServiceExtensionAbility(connection: number): Promise\<void>;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1399,7 +1423,8 @@ disconnectServiceExtensionAbility(connection: number, callback:AsyncCallback\<vo
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1549,7 +1574,8 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1611,7 +1637,8 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -1675,7 +1702,8 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......
......@@ -43,11 +43,11 @@ Ability初次启动原因,该类型为枚举,可配合[Ability](js-apis-app-
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.launchReason == AbilityConstant.LaunchReason.START_ABILITY) {
if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
}
}
......@@ -69,11 +69,11 @@ Ability上次退出原因,该类型为枚举,可配合[Ability](js-apis-app-
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launcherParam.lastExitReason == AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
}
}
......@@ -95,7 +95,7 @@ Ability迁移结果,该类型为枚举,可配合[Ability](js-apis-app-abilit
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onContinue(wantParam) {
......@@ -152,11 +152,11 @@ this.context.startAbility(want, option).then(()={
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onMemoryLevel(level) {
if (level == AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
if (level === AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
console.log("The memory of device is critical, please release some memory.");
}
}
......@@ -181,7 +181,7 @@ class MyAbility extends UIAbility {
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
......@@ -204,11 +204,11 @@ class MyAbility extends UIAbility {
**示例:**
```ts
import UIAbility form '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
if (reason == AbilityConstant.StateType.CONTINUATION) {
if (reason === AbilityConstant.StateType.CONTINUATION) {
console.log("Save the ability data when the ability continuation.");
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
......
......@@ -46,15 +46,14 @@ getAbilityDelegator(): AbilityDelegator
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.ohos.example",
abilityName: "MainAbility"
}
abilityDelegator.startAbility(want, (err)=>{
if (err.code != 0) {
};
abilityDelegator.startAbility(want, (err) => {
if (err.code !== 0) {
console.log("Success start ability.");
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
......@@ -81,7 +80,7 @@ getArguments(): AbilityDelegatorArgs
```ts
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var args = AbilityDelegatorRegistry.getArguments();
let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
......
......@@ -29,6 +29,14 @@ onAbilityCreate(ability: UIAbility): void;
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
}
};
```
## AbilityLifecycleCallback.onWindowStageCreate
......@@ -45,6 +53,14 @@ onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
}
};
```
## AbilityLifecycleCallback.onWindowStageActive
......@@ -61,6 +77,14 @@ onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
}
};
```
## AbilityLifecycleCallback.onWindowStageInactive
......@@ -77,6 +101,14 @@ onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
}
};
```
## AbilityLifecycleCallback.onWindowStageDestroy
......@@ -93,6 +125,14 @@ onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | 当前WindowStage对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
}
};
```
## AbilityLifecycleCallback.onAbilityDestroy
......@@ -108,6 +148,14 @@ onAbilityDestroy(ability: UIAbility): void;
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
}
};
```
## AbilityLifecycleCallback.onAbilityForeground
......@@ -123,6 +171,14 @@ onAbilityForeground(ability: UIAbility): void;
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
}
};
```
## AbilityLifecycleCallback.onAbilityBackground
......@@ -138,6 +194,14 @@ onAbilityBackground(ability: UIAbility): void;
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
}
};
```
## AbilityLifecycleCallback.onAbilityContinue
......@@ -153,45 +217,57 @@ onAbilityContinue(ability: UIAbility): void;
| -------- | -------- | -------- | -------- |
| ability | [UIAbility](js-apis-app-ability-uiAbility.md) | 是 | 当前Ability对象 |
**示例:**
```ts
let abilityLifecycleCallback = {
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
}
};
```
## AbilityLifecycleCallback使用
**示例:**
MyAbilityStage.ts
MyFirstAbility.ts
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityStage from "@ohos.app.ability.AbilityStage"
import AbilityStage from "@ohos.app.ability.AbilityStage";
import UIAbility from '@ohos.app.ability.UIAbility';
// 声明ability生命周期回调
let abilityLifecycleCallback = {
// 声明ability生命周期回调,需配置所有回调后才可以在applicationContext注册
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.");
},
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.");
}
}
};
export default class MyAbilityStage extends AbilityStage {
export default class MyFirstAbility extends UIAbility {
onCreate() {
console.log("MyAbilityStage onCreate");
// 1.通过context属性获取applicationContext
......@@ -207,11 +283,11 @@ export default class MyAbilityStage extends AbilityStage {
}
```
MyAbility.ts
MySecondAbility.ts
```ts
import UIAbility from "ohos.app.ability.UIAbility"
import UIAbility from "ohos.app.ability.UIAbility";
export default class MyAbility extends UIAbility {
export default class MySecondAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
// 3.通过applicationContext注销监听应用内生命周期
......
......@@ -10,7 +10,7 @@ AbilityManager模块提供获取、新增、修改Ability相关信息和状态
## 导入模块
```ts
import abilityManager from '@ohos.app.ability.abilityManager'
import abilityManager from '@ohos.app.ability.abilityManager';
```
## AbilityState
......@@ -46,29 +46,39 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
| config | [Configuration](js-apis-app-ability-configuration.md) | 是 | 新的配置项,仅需配置需要更新的项。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
var config = {
language: 'Zh-Hans',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
import abilityManager from '@ohos.app.ability.abilityManager';
const config = {
language: 'Zh-Hans', // 简体中文
colorMode: COLOR_MODE_LIGHT, // 浅色模式
direction: DIRECTION_VERTICAL, // 垂直方向
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为"sdpi"
displayId: 1, // 应用在Id为1的物理屏上显示
hasPointerDevice: true, // 指针类型设备已连接
};
try {
abilityManager.updateConfiguration(config, (err) => {
if (err.code != 0) {
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));
}
```
......@@ -94,17 +104,27 @@ updateConfiguration(config: Configuration): Promise\<void>
| ---------------------------------------- | ------- |
| Promise\<void> | 以Promise方式返回接口运行结果息,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
var config = {
language: 'Zh-Hans',
colorMode: COLOR_MODE_LIGHT,
direction: DIRECTION_VERTICAL,
screenDensity: SCREEN_DENSITY_SDPI,
displayId: 1,
hasPointerDevice: true,
}
import abilityManager from '@ohos.app.ability.abilityManager';
const config = {
language: 'Zh-Hans', // 简体中文
colorMode: COLOR_MODE_LIGHT, // 浅色模式
direction: DIRECTION_VERTICAL, // 垂直方向
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为"sdpi"
displayId: 1, // 应用在Id为1的物理屏上显示
hasPointerDevice: true, // 指针类型设备已连接
};
try {
abilityManager.updateConfiguration(config).then(() => {
......@@ -113,8 +133,8 @@ try {
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));
}
```
......@@ -134,20 +154,30 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): vo
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos((err,data) => {
if (err.code != 0) {
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));
}
```
......@@ -167,9 +197,19 @@ getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
| ---------------------------------------- | ------- |
| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的ability信息,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
......@@ -177,8 +217,8 @@ try {
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));
}
```
......@@ -196,25 +236,35 @@ getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<Ext
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | 是 | 获取消息数量的最大限制。 |
| upperLimit | number | 是 | 获取消息数量的最大限制,最大为2<sup>31</sup>-1。 |
| callback | AsyncCallback\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 是 | 以回调方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
var upperLimit = 0;
import abilityManager from '@ohos.app.ability.abilityManager';
let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err,data) => {
if (err.code != 0) {
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));
}
```
......@@ -232,7 +282,7 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ---------------------------------------- | ---- | -------------- |
| upperLimit | number | 是 | 获取消息数量的最大限制。 |
| upperLimit | number | 是 | 获取消息数量的最大限制,最大为2<sup>31</sup>-1。 |
**返回值:**
......@@ -240,10 +290,20 @@ getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningIn
| ---------------------------------------- | ------- |
| Promise\<Array\<[ExtensionRunningInfo](js-apis-inner-application-extensionRunningInfo.md)>> | 以Promise方式返回接口运行结果及运行中的extension信息,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
var upperLimit = 0;
import abilityManager from '@ohos.app.ability.abilityManager';
let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
......@@ -252,8 +312,8 @@ try {
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));
}
```
......@@ -271,11 +331,21 @@ getTopAbility(callback: AsyncCallback\<ElementName>): void;
| --------- | ---------------------------------------- | ---- | -------------- |
| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 以回调方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
abilityManager.getTopAbility((err,data) => {
if (err.code != 0) {
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility((err, data) => {
if (err.code !== 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
......@@ -297,9 +367,19 @@ getTopAbility(): Promise\<ElementName>;
| ---------------------------------------- | ------- |
| Promise\<[ElementName](js-apis-bundleManager-elementName.md)>| 以Promise方式返回接口运行结果及应用名,可进行错误处理或其他自定义处理。 |
**错误码**
| 错误码ID | 错误信息 |
| ------- | -------- |
| 16000050 | Internal error. |
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例**
```ts
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility success, data: " + JSON.stringify(data));
}).catch((err) => {
......
......@@ -26,6 +26,8 @@ onCreate(): void
**示例:**
```ts
import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
......@@ -57,6 +59,8 @@ onAcceptWant(want: Want): string;
**示例:**
```ts
import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
......@@ -83,6 +87,8 @@ onConfigurationUpdate(newConfig: Configuration): void;
**示例:**
```ts
import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, language:' + config.language);
......@@ -107,6 +113,8 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
**示例:**
```ts
import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
......
......@@ -8,7 +8,7 @@ appRecovery模块提供了应用在故障状态下的恢复能力。
## 导入模块
```ts
import appRecovery from '@ohos.app.ability.appRecovery'
import appRecovery from '@ohos.app.ability.appRecovery';
```
......@@ -67,10 +67,17 @@ enableAppRecovery(restart?: [RestartFlag](#apprecoveryrestartflag), saveOccasion
**示例:**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class MyAbilityStage extends AbilityStage {
import UIAbility from '@ohos.app.ability.UIAbility';
export default class MyAbility extends UIAbility {
onCreate() {
appRecovery.enableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR, SaveModeFlag::SAVE_WITH_FILE);
appRecovery.enableAppRecovery(
appRecovery.RestartFlag::ALWAYS_RESTART,
appRecovery.SaveOccasionFlag::SAVE_WHEN_ERROR,
appRecovery.SaveModeFlag::SAVE_WITH_FILE
);
}
}
```
......@@ -87,12 +94,20 @@ restartApp(): void;
**示例:**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import errorManager from '@ohos.app.ability.errorManager';
var observer = {
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.restartApp();
}
};
try {
errorManager.on("error", observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
......@@ -113,11 +128,19 @@ saveAppState(): boolean;
**示例:**
```ts
import appRecovery from '@ohos.app.ability.appRecovery';
import errorManager from '@ohos.app.ability.errorManager';
var observer = {
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
appRecovery.saveAppState();
}
};
try {
errorManager.on("error", observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
}
```
......@@ -332,7 +332,8 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -412,7 +413,8 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -573,7 +575,8 @@ release(): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -628,7 +631,8 @@ on(method: string, callback: CalleeCallback): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -693,7 +697,8 @@ off(method: string): void;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......
......@@ -52,7 +52,8 @@ createBundleContext(bundleName: string): Context;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -91,7 +92,8 @@ createModuleContext(moduleName: string): Context;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......@@ -129,7 +131,8 @@ createModuleContext(bundleName: string, moduleName: string): Context;
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | If the input parameter is not valid parameter. |
其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册