提交 e7d27868 编写于 作者: Z zhancaijin

fixed feb75270 from https://gitee.com/zhancaijin/docs/pulls/16934

update AppRecovery errorManager function
Signed-off-by: Nzhancaijin <zhancaijin1@huawei.com>
上级 af0a8d25
...@@ -94,12 +94,12 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant' ...@@ -94,12 +94,12 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
#### 主动触发保存和恢复 #### 主动触发保存和恢复
- 定义和注册[ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) callback - 定义和注册[ErrorObserver](../reference/apis/js-apis-inner-application-errorObserver.md) callback,具体可参考[errorManager](../reference/apis/js-apis-app-ability-errorManager.md)里的使用方法。
```ts ```ts
var registerId = -1; var registerId = -1;
var callback = { var callback = {
onUnhandledException: function (errMsg) { onUnhandledException(errMsg) {
console.log(errMsg); console.log(errMsg);
appRecovery.saveAppState(); appRecovery.saveAppState();
appRecovery.restartApp(); appRecovery.restartApp();
...@@ -111,7 +111,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant' ...@@ -111,7 +111,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
console.log("[Demo] MainAbility onWindowStageCreate") console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.registerObserver = (() => { globalThis.registerObserver = (() => {
registerId = errorManager.registerErrorObserver(callback); registerId = errorManager.on('error', callback);
}) })
windowStage.loadContent("pages/index", null); windowStage.loadContent("pages/index", null);
...@@ -127,7 +127,7 @@ callback触发appRecovery.saveAppState()调用后,会触发MainAbility的onSav ...@@ -127,7 +127,7 @@ callback触发appRecovery.saveAppState()调用后,会触发MainAbility的onSav
// Ability has called to save app data // Ability has called to save app data
console.log("[Demo] MainAbility onSaveState") console.log("[Demo] MainAbility onSaveState")
wantParams["myData"] = "my1234567"; wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE; return AbilityConstant.OnSaveResult.ALL_AGREE;
} }
``` ```
...@@ -157,8 +157,8 @@ onWindowStageDestroy() { ...@@ -157,8 +157,8 @@ onWindowStageDestroy() {
console.log("[Demo] MainAbility onWindowStageDestroy") console.log("[Demo] MainAbility onWindowStageDestroy")
globalThis.unRegisterObserver = (() => { globalThis.unRegisterObserver = (() => {
errorManager.unregisterErrorObserver(registerId, (result) => { errorManager.off('error', registerId, (err) => {
console.log("[Demo] result " + result.code + ";" + result.message) console.error("[Demo] err:", err);
}); });
}) })
} }
...@@ -186,7 +186,7 @@ export default class MainAbility extends Ability { ...@@ -186,7 +186,7 @@ export default class MainAbility extends Ability {
// Ability has called to save app data // Ability has called to save app data
console.log("[Demo] MainAbility onSaveState") console.log("[Demo] MainAbility onSaveState")
wantParams["myData"] = "my1234567"; wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE; return AbilityConstant.OnSaveResult.ALL_AGREE;
} }
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册