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

!14526 翻译已完成13383

Merge pull request !14526 from shawn_he/13383-b
......@@ -83,7 +83,7 @@ export default class MyAbilityStage extends AbilityStage {
### 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.
The following is an example of **MainAbility**:
The following is an example of **EntryAbility**:
#### Importing the Service Package
......@@ -109,7 +109,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
onWindowStageCreate(windowStage) {
// Main window is created. Set a main page for this ability.
console.log("[Demo] MainAbility onWindowStageCreate")
console.log("[Demo] EntryAbility onWindowStageCreate")
globalThis.registerObserver = (() => {
registerId = errorManager.registerErrorObserver(callback);
......@@ -121,12 +121,12 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant'
- 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
onSaveState(state, wantParams) {
// Save application data.
console.log("[Demo] MainAbility onSaveState")
console.log("[Demo] EntryAbility onSaveState")
wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE;
}
......@@ -134,12 +134,12 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state,
- 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
storage: LocalStorage
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) {
this.storage = new LocalStorage();
......@@ -155,7 +155,7 @@ onCreate(want, launchParam) {
```ts
onWindowStageDestroy() {
// Main window is destroyed to release UI resources.
console.log("[Demo] MainAbility onWindowStageDestroy")
console.log("[Demo] EntryAbility onWindowStageDestroy")
globalThis.unRegisterObserver = (() => {
errorManager.unregisterErrorObserver(registerId, (result) => {
......@@ -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.
```ts
export default class MainAbility extends Ability {
export default class EntryAbility extends Ability {
storage: LocalStorage
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
console.log("[Demo] EntryAbility onCreate")
globalThis.abilityWant = want;
if (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY) {
this.storage = new LocalStorage();
......@@ -185,7 +185,7 @@ export default class MainAbility extends Ability {
onSaveState(state, wantParams) {
// Save application data.
console.log("[Demo] MainAbility onSaveState")
console.log("[Demo] EntryAbility onSaveState")
wantParams["myData"] = "my1234567";
return AbilityConstant.onSaveResult.ALL_AGREE;
}
......
......@@ -36,8 +36,8 @@ When an asynchronous callback is used, the return value can be processed directl
## Development Example
```ts
import Ability from '@ohos.application.Ability'
import errorManager from '@ohos.application.errorManager'
import UIAbility from '@ohos.app.ability.UIAbility';
import errorManager from '@ohos.application.errorManager';
var registerId = -1;
var callback = {
......@@ -45,15 +45,15 @@ var callback = {
console.log(errMsg);
}
}
export default class MainAbility extends Ability {
export default class EntryAbility extends Ability {
onCreate(want, launchParam) {
console.log("[Demo] MainAbility onCreate")
console.log("[Demo] EntryAbility onCreate")
registerId = errorManager.registerErrorObserver(callback);
globalThis.abilityWant = want;
}
onDestroy() {
console.log("[Demo] MainAbility onDestroy")
console.log("[Demo] EntryAbility onDestroy")
errorManager.unregisterErrorObserver(registerId, (result) => {
console.log("[Demo] result " + result.code + ";" + result.message)
});
......@@ -61,7 +61,7 @@ export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// Main window is created for this ability.
console.log("[Demo] MainAbility onWindowStageCreate")
console.log("[Demo] EntryAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
......@@ -74,17 +74,17 @@ export default class MainAbility extends Ability {
onWindowStageDestroy() {
// Main window is destroyed to release UI resources.
console.log("[Demo] MainAbility onWindowStageDestroy")
console.log("[Demo] EntryAbility onWindowStageDestroy")
}
onForeground() {
// Ability is brought to the foreground.
console.log("[Demo] MainAbility onForeground")
console.log("[Demo] EntryAbility onForeground")
}
onBackground() {
// 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
```js
import hilog from '@ohos.hilog';
import Ability from '@ohos.application.Ability'
import UIAbility from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window'
import hiAppEvent from '@ohos.hiviewdfx.hiAppEvent'
export default class EntryAbility extends Ability {
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
......
......@@ -49,7 +49,7 @@ Example of the **config.json** file:
],
"commonEvents": [
{
"name": ".MainAbility",
"name": ".EntryAbility",
"permission": "ohos.permission.GET_BUNDLE_INFO",
"data": [
"com.example.demo",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册