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

!9905 翻译完成:8751+8711+8895 修复Stage模型startAbility示例错误( data为undefined)

Merge pull request !9905 from wusongqing/TR8751
...@@ -108,7 +108,9 @@ To create Page abilities for an application in the stage model, you must impleme ...@@ -108,7 +108,9 @@ To create Page abilities for an application in the stage model, you must impleme
} }
``` ```
### Obtaining AbilityStage and Ability Configurations ### Obtaining AbilityStage and Ability Configurations
Both the `AbilityStage` and `Ability` classes have the `context` attribute. An application can obtain the context of an `Ability` instance through `this.context` to obtain the configuration details. The following example shows how an application obtains the bundle code directory, HAP file name, ability name, and system language through the `context` attribute in the `AbilityStage` class. The sample code is as follows: Both the `AbilityStage` and `Ability` classes have the `context` attribute. An application can obtain the context of an `Ability` instance through `this.context` to obtain the configuration details.
The following example shows how an application obtains the bundle code directory, HAP file name, ability name, and system language through the `context` attribute in the `AbilityStage` class. The sample code is as follows:
```ts ```ts
import AbilityStage from "@ohos.application.AbilityStage" import AbilityStage from "@ohos.application.AbilityStage"
...@@ -123,7 +125,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -123,7 +125,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("MyAbilityStage hap module mainAbilityName" + currentHapModuleInfo.mainAbilityName) console.log("MyAbilityStage hap module mainAbilityName" + currentHapModuleInfo.mainAbilityName)
let config = this.context.config let config = this.context.config
console.log("MainAbility config language" + config.language) console.log("MyAbilityStage config language" + config.language)
} }
} }
``` ```
...@@ -142,7 +144,7 @@ export default class MainAbility extends Ability { ...@@ -142,7 +144,7 @@ export default class MainAbility extends Ability {
console.log("MainAbility ability name" + abilityInfo.name) console.log("MainAbility ability name" + abilityInfo.name)
let config = this.context.config let config = this.context.config
console.log("MainAbility config language" + config.language) console.log("MyAbilityStage config language" + config.language)
} }
} }
``` ```
......
...@@ -127,7 +127,7 @@ Starts an ability. This API uses a promise to return the result. ...@@ -127,7 +127,7 @@ Starts an ability. This API uses a promise to return the result.
windowMode: 0, windowMode: 0,
}; };
this.context.startAbility(want, options) this.context.startAbility(want, options)
.then((data) => { .then(() => {
console.log('Operation successful.') console.log('Operation successful.')
}).catch((error) => { }).catch((error) => {
console.log('Operation failed.'); console.log('Operation failed.');
...@@ -407,8 +407,8 @@ Starts a new Service Extension ability. This API uses a promise to return the re ...@@ -407,8 +407,8 @@ Starts a new Service Extension ability. This API uses a promise to return the re
"abilityName": "MainAbility" "abilityName": "MainAbility"
}; };
this.context.startServiceExtensionAbility(want) this.context.startServiceExtensionAbility(want)
.then((data) => { .then(() => {
console.log('---------- startServiceExtensionAbility success, data: -----------', data); console.log('---------- startServiceExtensionAbility success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startServiceExtensionAbility fail, err: -----------', err); console.log('---------- startServiceExtensionAbility fail, err: -----------', err);
...@@ -477,8 +477,8 @@ Starts a new Service Extension ability with the account ID specified. This API u ...@@ -477,8 +477,8 @@ Starts a new Service Extension ability with the account ID specified. This API u
}; };
var accountId = 100; var accountId = 100;
this.context.startServiceExtensionAbilityWithAccount(want,accountId) this.context.startServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => { .then(() => {
console.log('---------- startServiceExtensionAbilityWithAccount success, data: -----------', data); console.log('---------- startServiceExtensionAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err); console.log('---------- startServiceExtensionAbilityWithAccount fail, err: -----------', err);
...@@ -539,8 +539,8 @@ Stops a Service Extension ability in the same application. This API uses a promi ...@@ -539,8 +539,8 @@ Stops a Service Extension ability in the same application. This API uses a promi
"abilityName": "MainAbility" "abilityName": "MainAbility"
}; };
this.context.stopServiceExtensionAbility(want) this.context.stopServiceExtensionAbility(want)
.then((data) => { .then(() => {
console.log('---------- stopServiceExtensionAbility success, data: -----------', data); console.log('---------- stopServiceExtensionAbility success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- stopServiceExtensionAbility fail, err: -----------', err); console.log('---------- stopServiceExtensionAbility fail, err: -----------', err);
...@@ -610,8 +610,8 @@ Stops a Service Extension ability in the same application with the account ID sp ...@@ -610,8 +610,8 @@ Stops a Service Extension ability in the same application with the account ID sp
}; };
var accountId = 100; var accountId = 100;
this.context.stopServiceExtensionAbilityWithAccount(want,accountId) this.context.stopServiceExtensionAbilityWithAccount(want,accountId)
.then((data) => { .then(() => {
console.log('---------- stopServiceExtensionAbilityWithAccount success, data: -----------', data); console.log('---------- stopServiceExtensionAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err); console.log('---------- stopServiceExtensionAbilityWithAccount fail, err: -----------', err);
...@@ -658,8 +658,8 @@ Terminates this ability. This API uses a promise to return the result. ...@@ -658,8 +658,8 @@ Terminates this ability. This API uses a promise to return the result.
**Example** **Example**
```js ```js
this.context.terminateSelf().then((data) => { this.context.terminateSelf().then(() => {
console.log('success:' + JSON.stringify(data)); console.log('success');
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
...@@ -839,8 +839,8 @@ Disconnects a connection. This API uses a promise to return the result. ...@@ -839,8 +839,8 @@ Disconnects a connection. This API uses a promise to return the result.
```js ```js
var connectionNumber = 0; var connectionNumber = 0;
this.context.disconnectAbility(connectionNumber).then((data) => { this.context.disconnectAbility(connectionNumber).then(() => {
console.log('disconnectAbility success, data: ', data); console.log('disconnectAbility success');
}).catch((err) => { }).catch((err) => {
console.log('disconnectAbility fail, err: ', err); console.log('disconnectAbility fail, err: ', err);
}); });
...@@ -1020,8 +1020,8 @@ Starts an ability with the account ID specified. This API uses a promise to retu ...@@ -1020,8 +1020,8 @@ Starts an ability with the account ID specified. This API uses a promise to retu
windowMode: 0, windowMode: 0,
}; };
this.context.startAbilityWithAccount(want, accountId, options) this.context.startAbilityWithAccount(want, accountId, options)
.then((data) => { .then(() => {
console.log('---------- startAbilityWithAccount success, data: -----------', data); console.log('---------- startAbilityWithAccount success -----------');
}) })
.catch((err) => { .catch((err) => {
console.log('---------- startAbilityWithAccount fail, err: -----------', err); console.log('---------- startAbilityWithAccount fail, err: -----------', err);
...@@ -1134,8 +1134,8 @@ Sets a label for this ability in the mission. This API uses a promise to return ...@@ -1134,8 +1134,8 @@ Sets a label for this ability in the mission. This API uses a promise to return
**Example** **Example**
```js ```js
this.context.setMissionLabel("test").then((data) => { this.context.setMissionLabel("test").then(() => {
console.log('success:' + JSON.stringify(data)); console.log('success');
}).catch((error) => { }).catch((error) => {
console.log('failed:' + JSON.stringify(error)); console.log('failed:' + JSON.stringify(error));
}); });
...@@ -1224,8 +1224,8 @@ Sets an icon for this ability in the mission. This API uses a promise to return ...@@ -1224,8 +1224,8 @@ Sets an icon for this ability in the mission. This API uses a promise to return
console.log('--------- createPixelMap fail, err: ---------', err) console.log('--------- createPixelMap fail, err: ---------', err)
}); });
this.context.setMissionIcon(imagePixelMap) this.context.setMissionIcon(imagePixelMap)
.then((data) => { .then(() => {
console.log('-------------- setMissionIcon success, data: -------------', data); console.log('-------------- setMissionIcon success -------------');
}) })
.catch((err) => { .catch((err) => {
console.log('-------------- setMissionIcon fail, err: -------------', err); console.log('-------------- setMissionIcon fail, err: -------------', err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册