提交 4cc454f8 编写于 作者: X xuzhihao

Feature: fix UIAbility description

Signed-off-by: Nxuzhihao <xuzhihao16@huawei.com>
上级 bd8a03aa
...@@ -412,7 +412,7 @@ export default class FuncAbility extends UIAbility { ...@@ -412,7 +412,7 @@ export default class FuncAbility extends UIAbility {
``` ```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 当被调用方[Ability的启动模式](uiability-launch-type.md)设置为standard启动模式时,每次启动都会创建一个新的实例,那么[onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)回调就不会被用到。 > 当被调用方[UIAbility的启动模式](uiability-launch-type.md)设置为standard启动模式时,每次启动都会创建一个新的实例,那么[onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)回调就不会被用到。
## 通过Call调用实现UIAbility交互(仅对系统应用开放) ## 通过Call调用实现UIAbility交互(仅对系统应用开放)
...@@ -485,12 +485,12 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe ...@@ -485,12 +485,12 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
在Callee被调用端,需要实现指定方法的数据接收回调函数、数据的序列化及反序列化方法。在需要接收数据期间,通过on接口注册监听,无需接收数据时通过off接口解除监听。 在Callee被调用端,需要实现指定方法的数据接收回调函数、数据的序列化及反序列化方法。在需要接收数据期间,通过on接口注册监听,无需接收数据时通过off接口解除监听。
1. 配置Ability的启动模式。 1. 配置UIAbility的启动模式。
配置module.json5,将CalleeAbility配置为单实例"singleton"。 配置module.json5,将CalleeAbility配置为单实例"singleton"。
| Json字段 | 字段说明 | | Json字段 | 字段说明 |
| -------- | -------- | | -------- | -------- |
| "launchType" | Ability的启动模式,设置为"singleton"类型。 | | "launchType" | UIAbility的启动模式,设置为"singleton"类型。 |
Ability配置标签示例如下: Ability配置标签示例如下:
...@@ -510,7 +510,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe ...@@ -510,7 +510,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
2. 导入UIAbility模块。 2. 导入UIAbility模块。
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
``` ```
3. 定义约定的序列化数据。 3. 定义约定的序列化数据。
...@@ -542,7 +542,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe ...@@ -542,7 +542,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
``` ```
4. 实现Callee.on监听及Callee.off解除监听。 4. 实现Callee.on监听及Callee.off解除监听。
被调用端Callee的监听函数注册时机,取决于应用开发者。注册监听之前的数据不会被处理,取消监听之后的数据不会被处理。如下示例在Ability的onCreate注册'MSG_SEND_METHOD'监听,在onDestroy取消监听,收到序列化数据后作相应处理并返回,应用开发者根据实际需要做相应处理。具体示例代码如下: 被调用端Callee的监听函数注册时机,取决于应用开发者。注册监听之前的数据不会被处理,取消监听之后的数据不会被处理。如下示例在UIAbility的onCreate注册'MSG_SEND_METHOD'监听,在onDestroy取消监听,收到序列化数据后作相应处理并返回,应用开发者根据实际需要做相应处理。具体示例代码如下:
```ts ```ts
...@@ -562,7 +562,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe ...@@ -562,7 +562,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`); return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`);
} }
export default class CalleeAbility extends Ability { export default class CalleeAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
try { try {
this.callee.on(MSG_SEND_METHOD, sendMsgCallback); this.callee.on(MSG_SEND_METHOD, sendMsgCallback);
...@@ -587,11 +587,11 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe ...@@ -587,11 +587,11 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
1. 导入UIAbility模块。 1. 导入UIAbility模块。
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
``` ```
2. 获取Caller通信接口。 2. 获取Caller通信接口。
Ability的context属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取Ability实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease监听。应用开发者根据实际需要做相应处理。 UIAbility的context属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取UIAbility实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease监听。应用开发者根据实际需要做相应处理。
```ts ```ts
......
# @ohos.app.ability.UIAbility (UIAbility) # @ohos.app.ability.UIAbility (UIAbility)
Ability模块提供对Ability生命周期、上下文环境等调用管理的能力,包括Ability创建、销毁、转储客户端信息等。 UIAbility模块提供对Ability生命周期、上下文环境等调用管理的能力,包括Ability创建、销毁、转储客户端信息等。
该模块提供以下Ability相关的常用功能: 该模块提供以下UIAbility相关的常用功能:
- [Caller](#caller):通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。 - [Caller](#caller):通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
- [Callee](#callee):通用组件服务端注册和解除客户端caller通知送信的callback接口。 - [Callee](#callee):通用组件服务端注册和解除客户端caller通知送信的callback接口。
...@@ -15,7 +15,7 @@ Ability模块提供对Ability生命周期、上下文环境等调用管理的能 ...@@ -15,7 +15,7 @@ Ability模块提供对Ability生命周期、上下文环境等调用管理的能
## 导入模块 ## 导入模块
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
``` ```
## 属性 ## 属性
...@@ -29,11 +29,11 @@ import Ability from '@ohos.app.ability.UIAbility'; ...@@ -29,11 +29,11 @@ import Ability from '@ohos.app.ability.UIAbility';
| lastRequestWant | [Want](js-apis-app-ability-want.md) | 是 | 否 | Ability最后请求时的参数。| | lastRequestWant | [Want](js-apis-app-ability-want.md) | 是 | 否 | Ability最后请求时的参数。|
| callee | [Callee](#callee) | 是 | 否 | 调用Stub(桩)服务对象。| | callee | [Callee](#callee) | 是 | 否 | 调用Stub(桩)服务对象。|
## Ability.onCreate ## UIAbility.onCreate
onCreate(want: Want, param: AbilityConstant.LaunchParam): void; onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
Ability创建时回调,执行初始化业务逻辑操作。 UIAbility创建时回调,执行初始化业务逻辑操作。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
...@@ -41,13 +41,13 @@ Ability创建时回调,执行初始化业务逻辑操作。 ...@@ -41,13 +41,13 @@ Ability创建时回调,执行初始化业务逻辑操作。
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-app-ability-want.md) | 是 | 当前Ability的Want类型信息,包括ability名称、bundle名称等。 | | want | [Want](js-apis-app-ability-want.md) | 是 | 当前UIAbility的Want类型信息,包括ability名称、bundle名称等。 |
| param | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | 创建&nbsp;ability、上次异常退出的原因信息。 | | param | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | 创建&nbsp;ability、上次异常退出的原因信息。 |
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onCreate(want, param) { onCreate(want, param) {
console.log('onCreate, want:' + want.abilityName); console.log('onCreate, want:' + want.abilityName);
} }
...@@ -55,7 +55,7 @@ Ability创建时回调,执行初始化业务逻辑操作。 ...@@ -55,7 +55,7 @@ Ability创建时回调,执行初始化业务逻辑操作。
``` ```
## Ability.onWindowStageCreate ## UIAbility.onWindowStageCreate
onWindowStageCreate(windowStage: window.WindowStage): void onWindowStageCreate(windowStage: window.WindowStage): void
...@@ -72,7 +72,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void ...@@ -72,7 +72,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
console.log('onWindowStageCreate'); console.log('onWindowStageCreate');
} }
...@@ -80,7 +80,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void ...@@ -80,7 +80,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
``` ```
## Ability.onWindowStageDestroy ## UIAbility.onWindowStageDestroy
onWindowStageDestroy(): void onWindowStageDestroy(): void
...@@ -91,7 +91,7 @@ onWindowStageDestroy(): void ...@@ -91,7 +91,7 @@ onWindowStageDestroy(): void
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onWindowStageDestroy() { onWindowStageDestroy() {
console.log('onWindowStageDestroy'); console.log('onWindowStageDestroy');
} }
...@@ -99,7 +99,7 @@ onWindowStageDestroy(): void ...@@ -99,7 +99,7 @@ onWindowStageDestroy(): void
``` ```
## Ability.onWindowStageRestore ## UIAbility.onWindowStageRestore
onWindowStageRestore(windowStage: window.WindowStage): void onWindowStageRestore(windowStage: window.WindowStage): void
...@@ -116,7 +116,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void ...@@ -116,7 +116,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onWindowStageRestore(windowStage) { onWindowStageRestore(windowStage) {
console.log('onWindowStageRestore'); console.log('onWindowStageRestore');
} }
...@@ -124,18 +124,18 @@ onWindowStageRestore(windowStage: window.WindowStage): void ...@@ -124,18 +124,18 @@ onWindowStageRestore(windowStage: window.WindowStage): void
``` ```
## Ability.onDestroy ## UIAbility.onDestroy
onDestroy(): void; onDestroy(): void;
Ability生命周期回调,在销毁时回调,执行资源清理等操作。 UIAbility生命周期回调,在销毁时回调,执行资源清理等操作。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onDestroy() { onDestroy() {
console.log('onDestroy'); console.log('onDestroy');
} }
...@@ -143,18 +143,18 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。 ...@@ -143,18 +143,18 @@ Ability生命周期回调,在销毁时回调,执行资源清理等操作。
``` ```
## Ability.onForeground ## UIAbility.onForeground
onForeground(): void; onForeground(): void;
Ability生命周期回调,当应用从后台转到前台时触发。 UIAbility生命周期回调,当应用从后台转到前台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onForeground() { onForeground() {
console.log('onForeground'); console.log('onForeground');
} }
...@@ -162,18 +162,18 @@ Ability生命周期回调,当应用从后台转到前台时触发。 ...@@ -162,18 +162,18 @@ Ability生命周期回调,当应用从后台转到前台时触发。
``` ```
## Ability.onBackground ## UIAbility.onBackground
onBackground(): void; onBackground(): void;
Ability生命周期回调,当应用从前台转到后台时触发。 UIAbility生命周期回调,当应用从前台转到后台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onBackground() { onBackground() {
console.log('onBackground'); console.log('onBackground');
} }
...@@ -181,7 +181,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。 ...@@ -181,7 +181,7 @@ Ability生命周期回调,当应用从前台转到后台时触发。
``` ```
## Ability.onContinue ## UIAbility.onContinue
onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult; onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
...@@ -215,7 +215,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult; ...@@ -215,7 +215,7 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
``` ```
## Ability.onNewWant ## UIAbility.onNewWant
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
...@@ -241,7 +241,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; ...@@ -241,7 +241,7 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
} }
``` ```
## Ability.onDump ## UIAbility.onDump
onDump(params: Array\<string>): Array\<string>; onDump(params: Array\<string>): Array\<string>;
...@@ -258,7 +258,7 @@ onDump(params: Array\<string>): Array\<string>; ...@@ -258,7 +258,7 @@ onDump(params: Array\<string>): Array\<string>;
**示例:** **示例:**
```ts ```ts
class myAbility extends Ability { class myUIAbility extends UIAbility {
onDump(params) { onDump(params) {
console.log('dump, params:' + JSON.stringify(params)); console.log('dump, params:' + JSON.stringify(params));
return ['params']; return ['params'];
...@@ -267,11 +267,11 @@ onDump(params: Array\<string>): Array\<string>; ...@@ -267,11 +267,11 @@ onDump(params: Array\<string>): Array\<string>;
``` ```
## Ability.onSaveState ## UIAbility.onSaveState
onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult; onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}): AbilityConstant.OnSaveResult;
该API配合[appRecovery](js-apis-app-ability-appRecovery.md)使用。在应用故障时,如果使能了自动保存状态,框架将回调onSaveState保存Ability状态。 该API配合[appRecovery](js-apis-app-ability-appRecovery.md)使用。在应用故障时,如果使能了自动保存状态,框架将回调onSaveState保存UIAbility状态。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore **系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
...@@ -286,7 +286,7 @@ onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any}) ...@@ -286,7 +286,7 @@ onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any})
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| AbilityConstant.OnSaveResult | 是否同意保存当前Ability的状态。 | | AbilityConstant.OnSaveResult | 是否同意保存当前UIAbility的状态。 |
**示例:** **示例:**
...@@ -339,7 +339,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;; ...@@ -339,7 +339,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{ // 自定义的Parcelable数据结构 class MyMessageAble{ // 自定义的Parcelable数据结构
name:'' name:''
str:'' str:''
...@@ -363,7 +363,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;; ...@@ -363,7 +363,7 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
}; };
let method = 'call_Function'; // 约定的通知消息字符串 let method = 'call_Function'; // 约定的通知消息字符串
let caller; let caller;
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: 'com.example.myservice', bundleName: 'com.example.myservice',
...@@ -420,7 +420,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ ...@@ -420,7 +420,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{ class MyMessageAble{
name:'' name:''
str:'' str:''
...@@ -444,7 +444,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ ...@@ -444,7 +444,7 @@ callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequ
}; };
let method = 'call_Function'; let method = 'call_Function';
let caller; let caller;
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: 'com.example.myservice', bundleName: 'com.example.myservice',
...@@ -492,9 +492,9 @@ release(): void; ...@@ -492,9 +492,9 @@ release(): void;
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let caller; let caller;
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: 'com.example.myservice', bundleName: 'com.example.myservice',
...@@ -533,9 +533,9 @@ release(): void; ...@@ -533,9 +533,9 @@ release(): void;
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.application.Ability';
let caller; let caller;
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: 'com.example.myservice', bundleName: 'com.example.myservice',
...@@ -584,9 +584,9 @@ release(): void; ...@@ -584,9 +584,9 @@ release(): void;
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
let caller; let caller;
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({ this.context.startAbilityByCall({
bundleName: 'com.example.myservice', bundleName: 'com.example.myservice',
...@@ -742,7 +742,7 @@ on(method: string, callback: CalleeCallback): void; ...@@ -742,7 +742,7 @@ on(method: string, callback: CalleeCallback): void;
**示例:** **示例:**
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{ class MyMessageAble{
name:'' name:''
str:'' str:''
...@@ -771,7 +771,7 @@ on(method: string, callback: CalleeCallback): void; ...@@ -771,7 +771,7 @@ on(method: string, callback: CalleeCallback): void;
pdata.readParcelable(msg); pdata.readParcelable(msg);
return new MyMessageAble('test1', 'Callee test'); return new MyMessageAble('test1', 'Callee test');
} }
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log('Callee onCreate is called'); console.log('Callee onCreate is called');
try { try {
...@@ -811,7 +811,7 @@ off(method: string): void; ...@@ -811,7 +811,7 @@ off(method: string): void;
```ts ```ts
import Ability from '@ohos.app.ability.UIAbility'; import Ability from '@ohos.app.ability.UIAbility';
let method = 'call_Function'; let method = 'call_Function';
export default class MainAbility extends Ability { export default class MainUIAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log('Callee onCreate is called'); console.log('Callee onCreate is called');
try { try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册