提交 a7cd13d1 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 3f4fa4bd
...@@ -83,7 +83,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -83,7 +83,7 @@ export default class MyAbilityStage extends AbilityStage {
### Saving and Restoring Data ### Saving and Restoring Data
After enabling **appRecovery**, you can use this function by either actively or passively saving the status and restoring data in the ability. After enabling **appRecovery**, you can use this function by either actively or passively saving the status and restoring data in the ability.
The following is an example of **MainAbility**: The following is an example of **EntryAbility**:
#### Importing the Service Package #### Importing the Service Package
...@@ -109,7 +109,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant' ...@@ -109,7 +109,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created. Set a main page for this ability. // Main window is created. Set a main page for this ability.
console.log("[Demo] MainAbility onWindowStageCreate") console.log("[Demo] EntryAbility onWindowStageCreate")
globalThis.registerObserver = (() => { globalThis.registerObserver = (() => {
registerId = errorManager.registerErrorObserver(callback); registerId = errorManager.registerErrorObserver(callback);
...@@ -121,12 +121,12 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant' ...@@ -121,12 +121,12 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
- Save data. - Save data.
After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, wantParams)** of **MainAbility** is triggered. After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, wantParams)** of **EntryAbility** is triggered.
```ts ```ts
onSaveState(state, wantParams) { onSaveState(state, wantParams) {
// Save application data. // Save application data.
console.log("[Demo] MainAbility onSaveState") console.log("[Demo] EntryAbility onSaveState")
wantParams["myData"] = "my1234567"; wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE; return AbilityConstant.onSaveResult.ALL_AGREE;
} }
...@@ -134,12 +134,12 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, ...@@ -134,12 +134,12 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state,
- Restore data. - Restore data.
After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onSaveState(state, wantParams)** of **MainAbility** is called, and the saved data is in **parameters** of **want**. After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onSaveState(state, wantParams)** of **EntryAbility** is called, and the saved data is in **parameters** of **want**.
```ts ```ts
storage: LocalStorage storage: LocalStorage
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate") console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want; globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) { if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
...@@ -155,7 +155,7 @@ onCreate(want, launchParam) { ...@@ -155,7 +155,7 @@ onCreate(want, launchParam) {
```ts ```ts
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed to release UI resources. // Main window is destroyed to release UI resources.
console.log("[Demo] MainAbility onWindowStageDestroy") console.log("[Demo] EntryAbility onWindowStageDestroy")
globalThis.unRegisterObserver = (() => { globalThis.unRegisterObserver = (() => {
errorManager.unregisterErrorObserver(registerId, (result) => { errorManager.unregisterErrorObserver(registerId, (result) => {
...@@ -170,10 +170,10 @@ onWindowStageDestroy() { ...@@ -170,10 +170,10 @@ onWindowStageDestroy() {
This is triggered by the recovery framework. You do not need to register **ErrorObserver callback**. You only need to implement **onSaveState** of the ability for status saving and **onCreate** of the ability for data restoration. This is triggered by the recovery framework. You do not need to register **ErrorObserver callback**. You only need to implement **onSaveState** of the ability for status saving and **onCreate** of the ability for data restoration.
```ts ```ts
export default class MainAbility extends Ability { export default class EntryAbility extends Ability {
storage: LocalStorage storage: LocalStorage
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate") console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want; globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) { if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) {
this.storage = new LocalStorage(); this.storage = new LocalStorage();
...@@ -185,7 +185,7 @@ export default class MainAbility extends Ability { ...@@ -185,7 +185,7 @@ export default class MainAbility extends Ability {
onSaveState(state, wantParams) { onSaveState(state, wantParams) {
// Save application data. // Save application data.
console.log("[Demo] MainAbility onSaveState") console.log("[Demo] EntryAbility onSaveState")
wantParams["myData"] = "my1234567"; wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE; return AbilityConstant.onSaveResult.ALL_AGREE;
} }
......
...@@ -36,8 +36,8 @@ When an asynchronous callback is used, the return value can be processed directl ...@@ -36,8 +36,8 @@ When an asynchronous callback is used, the return value can be processed directl
## Development Example ## Development Example
```ts ```ts
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import errorManager from '@ohos.application.errorManager' import errorManager from '@ohos.application.errorManager';
var registerId = -1; var registerId = -1;
var callback = { var callback = {
...@@ -45,15 +45,15 @@ var callback = { ...@@ -45,15 +45,15 @@ var callback = {
console.log(errMsg); console.log(errMsg);
} }
} }
export default class MainAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate") console.log("[Demo] EntryAbility onCreate")
registerId = errorManager.registerErrorObserver(callback); registerId = errorManager.registerErrorObserver(callback);
globalThis.abilityWant = want; globalThis.abilityWant = want;
} }
onDestroy() { onDestroy() {
console.log("[Demo] MainAbility onDestroy") console.log("[Demo] EntryAbility onDestroy")
errorManager.unregisterErrorObserver(registerId, (result) => { errorManager.unregisterErrorObserver(registerId, (result) => {
console.log("[Demo] result " + result.code + ";" + result.message) console.log("[Demo] result " + result.code + ";" + result.message)
}); });
...@@ -61,7 +61,7 @@ export default class MainAbility extends Ability { ...@@ -61,7 +61,7 @@ export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created for this ability. // Main window is created for this ability.
console.log("[Demo] MainAbility onWindowStageCreate") console.log("[Demo] EntryAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => { windowStage.loadContent("pages/index", (err, data) => {
if (err.code) { if (err.code) {
...@@ -74,17 +74,17 @@ export default class MainAbility extends Ability { ...@@ -74,17 +74,17 @@ export default class MainAbility extends Ability {
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed to release UI resources. // Main window is destroyed to release UI resources.
console.log("[Demo] MainAbility onWindowStageDestroy") console.log("[Demo] EntryAbility onWindowStageDestroy")
} }
onForeground() { onForeground() {
// Ability is brought to the foreground. // Ability is brought to the foreground.
console.log("[Demo] MainAbility onForeground") console.log("[Demo] EntryAbility onForeground")
} }
onBackground() { onBackground() {
// Ability is brought back to the background. // Ability is brought back to the background.
console.log("[Demo] MainAbility onBackground") console.log("[Demo] EntryAbility onBackground")
} }
}; };
``` ```
...@@ -49,11 +49,11 @@ The following example illustrates how to log and subscribe to button click event ...@@ -49,11 +49,11 @@ The following example illustrates how to log and subscribe to button click event
```js ```js
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window' import Window from '@ohos.window'
import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent' import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent'
export default class EntryAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
......
...@@ -49,7 +49,7 @@ Example of the **config.json** file: ...@@ -49,7 +49,7 @@ Example of the **config.json** file:
], ],
"commonEvents": [ "commonEvents": [
{ {
"name": ".MainAbility", "name": ".EntryAbility",
"permission": "ohos.permission.GET_BUNDLE_INFO", "permission": "ohos.permission.GET_BUNDLE_INFO",
"data": [ "data": [
"com.example.demo", "com.example.demo",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册