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

!22255 onCreate()与onNewWant()接口中参数名修改

Merge pull request !22255 from 陶家炜/tjw1
......@@ -13,8 +13,8 @@
|接口名 | 描述|
|:------ | :------|
| onContinue(wantParam : {[key: string]: any}): OnContinueResult | 迁移**发起端**在该回调中保存迁移所需要的数据,同时返回是否同意迁移:AGREE表示同意,REJECT表示拒绝;MISMATCH表示版本不匹配。 |
| onCreate(want: Want, param: AbilityConstant.LaunchParam): void; | 多实例应用迁移**目标端**在该回调中完成数据恢复,并触发页面恢复。 |
| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | 单实例应用迁移**目标端**在该回调中完成数据恢复,并触发页面恢复。 |
| onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void; | 多实例应用迁移**目标端**在该回调中完成数据恢复,并触发页面恢复。 |
| onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void; | 单实例应用迁移**目标端**在该回调中完成数据恢复,并触发页面恢复。 |
......@@ -22,7 +22,7 @@
![continuation_dev](figures/continuation-info.png)
迁移实际上是Ability携带数据的跨端启动。触发迁移动作时,会在A设备上通过系统回调应用的onContinue()方法,开发者需要在此方法中实现当前数据的保存。然后系统发起在B设备上的跨端启动,并将数据一同传输到B设备。B设备系统回调onCreate()/onNewWant()方法,开发者需要在此方法中实现传输过来的数据的恢复。
迁移实际上是Ability携带数据的跨端启动。触发迁移动作时,会在A设备上通过系统回调应用的onContinue()方法,开发者需要在此方法中实现当前数据的保存。然后系统发起在B设备上的跨端启动,并将数据一同传输到B设备。B设备系统回调onCreate()/onNewWant()方法,开发者需要在此方法中实现传输过来的数据的恢复。
## 开发步骤
......@@ -35,7 +35,7 @@
- 配置应用支持迁移
在module.json5中配置continuable字段:true表示支持迁移,false表示不支持,默认为false。配置为false的应用将被系统识别为无法迁移。
```javascript
{
"module": {
......@@ -47,14 +47,14 @@
}
}
```
- 配置应用启动类型
多实例应用在module.json5中将launchType字段配置为multiton,目标端将会拉起一个新的应用,并恢复页面;单实例将该字段配置为singleton,如果目标端应用已经打开,迁移将会将已有页面栈清空,并根据迁移数据恢复页面。关于单实例与多实例的更多信息详见[ability开发指导](./stage-ability.md)启动模式。
多实例:
```javascript
{
"module": {
......@@ -66,9 +66,9 @@
}
}
```
缺省或如下配置为单实例:
```javascript
{
"module": {
......@@ -80,20 +80,20 @@
}
}
```
- 申请分布式权限
支持跨端迁移的应用需要在module.json5申请分布式权限 DISTRIBUTED_DATASYNC。
```javascript
"requestPermissions": [
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
},
```
这个权限需要在应用首次启动的时候弹窗让用户授予,可以通过在ability的onWindowStageCreate中添加如下代码实现:
```javascript
requestPermissions = async () => {
let permissions: Array<string> = [
......@@ -130,7 +130,7 @@
}
}
```
2. 实现onContinue接口
......@@ -166,20 +166,20 @@
onCreate()接口在迁移目标端被调用,在目标端ability被拉起时,通知开发者同步已保存的内存数据和控件状态,完成后触发页面的恢复。如果不实现该接口中迁移相关逻辑,ability将会作为普通的启动方式拉起,无法恢复页面。
远端设备上,在onCreate()中根据launchReason判断该次启动是否为迁移LaunchReason.CONTINUATION
完成数据恢复后,开发者需要调用restoreWindowStage来触发页面恢复。
在入参want中也可以通过want.parameters.version来获取发起端的应用版本号。
示例
```javascript
import UIAbility from '@ohos.app.ability.UIAbility';
import distributedObject from '@ohos.data.distributedDataObject';
export default class EntryAbility extends UIAbility {
storage : LocalStorag;
onCreate(want, launchParam) {
Logger.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
......@@ -187,7 +187,7 @@
let workInput = want.parameters.work
Logger.info(`work input ${workInput}`)
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
......@@ -209,12 +209,12 @@
```javascript
import UIAbility from '@ohos.app.ability.UIAbility';
import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({data:undefined});
export default class EntryAbility extends UIAbility {
sessionId : string;
onContinue(wantParam : {[key: string]: any}) {
Logger.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
......@@ -243,33 +243,33 @@
```javascript
import UIAbility from '@ohos.app.ability.UIAbility';
import distributedObject from '@ohos.data.distributedDataObject';
var g_object = distributedObject.createDistributedObject({data:undefined});
export default class EntryAbility extends UIAbility {
storage : LocalStorag;
onCreate(want, launchParam) {
Logger.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get distributed data object session id from want params
this.sessionId = want.parameters.session
Logger.info(`onCreate for continuation sessionId: ${this.sessionId}`)
// in order to fetch from remote, reset g_object.data to undefined first
g_object.data = undefined;
// set session id, so it will fetch data from remote
g_object.setSessionId(this.sessionId);
AppStorage.SetOrCreate<string>('ContinueStudy', g_object.data)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
}
```
### 其他说明
1. 超时机制:
......
......@@ -45,13 +45,13 @@ Ability功能如下(Ability类,具体的API详见[接口文档](../reference
|接口名|描述|
|:------|:------|
|onCreate(want: Want, param: AbilityConstant.LaunchParam): void|Ability生命周期回调,Ability启动时被调用。|
|onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void|Ability生命周期回调,Ability启动时被调用。|
|onDestroy(): void|Ability生命周期回调,Ability销毁时被调用。|
|onWindowStageCreate(windowStage: window.WindowStage): void|Ability生命周期回调,创建window stage时被调用,应用开发者可通过window.WindowStage的接口执行页面加载等操作。|
|onWindowStageDestroy(): void|Ability生命周期回调,销毁window stage时被调用。|
|onForeground(): void|Ability生命周期回调,Ability切换至前台时被调用。|
|onBackground(): void|Ability生命周期回调,Ability切换至后台时被调用。|
|onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void|Ability回调,Ability的启动模式设置为单例时被调用。|
|onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void|Ability回调,Ability的启动模式设置为单例时被调用。|
|onConfigurationUpdated(config: Configuration): void|Ability回调,Ability的系统配置更新时被调用。|
### 实现AbilityStage及Ability生命周期
创建Stage模型的Page Ability应用,需实现AbilityStage接口及Ability生命周期接口,并使用窗口提供的方法设置页面。具体示例代码如下:
......@@ -79,29 +79,29 @@ Ability功能如下(Ability类,具体的API详见[接口文档](../reference
onCreate(want, launchParam) {
console.log("EntryAbility onCreate")
}
onDestroy() {
console.log("EntryAbility onDestroy")
}
onWindowStageCreate(windowStage) {
console.log("EntryAbility onWindowStageCreate")
windowStage.loadContent("pages/index").then(() => {
console.log("EntryAbility load content succeed")
}).catch((error) => {
console.error("EntryAbility load content failed with error: " + JSON.stringify(error))
})
}
onWindowStageDestroy() {
console.log("EntryAbility onWindowStageDestroy")
}
onForeground() {
console.log("EntryAbility onForeground")
}
onBackground() {
console.log("EntryAbility onBackground")
}
......@@ -277,7 +277,7 @@ async function reStartAbility() {
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onNewWant(want, launchParams) {
onNewWant(want, launchParam) {
globalThis.newWant = want
}
}
......
......@@ -22,7 +22,7 @@
跨端迁移流程如下图所示。
**图1** 跨端迁移流程图
**图1** 跨端迁移流程图
![hop-cross-device-migration](figures/hop-cross-device-migration.png)
......@@ -47,8 +47,8 @@
| **接口名** | **描述** |
| -------- | -------- |
| onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;OnContinueResult | 迁移发起端在该回调中保存迁移所需要的数据,同时返回是否同意迁移:<br/>-&nbsp;AGREE:表示同意。<br/>-&nbsp;REJECT:表示拒绝:如应用在onContinue中异常可以直接REJECT。<br/>-&nbsp;MISMATCH:表示版本不匹配:迁移发起端应用可以在onContinue中获取到迁移接收端应用的版本号,进行协商后,如果版本不匹配导致无法迁移,可以返回该错误。 |
| onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 应用迁移接收端为冷启动或多实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
| onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 迁移接收端为单实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
| onCreate(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 应用迁移接收端为冷启动或多实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
| onNewWant(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void; | 迁移接收端为单实例应用热启动时,在该回调中完成数据恢复,并触发页面恢复。详见[应用组件启动模式](uiability-launch-type.md) |
......@@ -89,18 +89,18 @@
- 迁移决策:开发者可以通过onContinue接口的返回值决定是否支持此次迁移,返回值信息见[接口说明](#接口说明)
示例如下:
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
let workInput = AppStorage.Get<string>('ContinueWork');
// set user input data into want params
wantParam["work"] = workInput // set user input data into want params
console.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
let workInput = AppStorage.Get<string>('ContinueWork');
// set user input data into want params
wantParam["work"] = workInput // set user input data into want params
console.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE
}
```
......@@ -109,44 +109,44 @@
- 目标端设备上,在onCreate中根据launchReason判断该次启动是否为迁移LaunchReason.CONTINUATION。
- 开发者可以从want中获取保存的迁移数据。
- 完成数据恢复后,开发者需要调用restoreWindowStage来触发页面恢复:包括页面栈信息。
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import distributedObject from '@ohos.data.distributedDataObject';
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onCreate(want, launchParam) {
console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get user data from want params
let workInput = want.parameters.work
console.info(`work input ${workInput}`)
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
import distributedObject from '@ohos.data.distributedDataObject';
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onCreate(want, launchParam) {
console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get user data from want params
let workInput = want.parameters.work
console.info(`work input ${workInput}`)
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
}
```
- 如果是单实例应用,需要额外实现onNewWant()接口,实现方式与onCreate()的实现相同。
- 在onNewWant()中判断迁移场景,恢复数据,并触发页面恢复
```ts
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onNewWant(want, launchParam) {
console.info(`EntryAbility onNewWant ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get user data from want params
let workInput = want.parameters.work
console.info(`work input ${workInput}`)
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
```ts
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onNewWant(want, launchParam) {
console.info(`EntryAbility onNewWant ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get user data from want params
let workInput = want.parameters.work
console.info(`work input ${workInput}`)
AppStorage.SetOrCreate<string>('ContinueWork', workInput)
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
}
6. **可选配置:** 在应用支持迁移特性时,默认开启应用迁移状态开关,根据应用当前任务获取焦点/失去焦点通知周边的可信设备当前任务可流转/取消流转。若应用需要在特定场景下才通知周边设备可流转,则需要在应用打开时设置迁移状态为INACTIVE,在后续的业务流程中需要迁移时再设置迁移状态为ACTIVE。接口见[setMissionContinueState](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextsetmissioncontinuestate10)
......@@ -182,8 +182,8 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import wantConstant from '@ohos.app.ability.wantConstant.d.ts';
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
wantParam[wantConstant.Params.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false;
return AbilityConstant.OnContinueResult.AGREE;
}
......@@ -202,8 +202,8 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import wantConstant from '@ohos.app.ability.wantConstant.d.ts';
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
onContinue(wantParam : {[key: string]: any}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
wantParam[wantConstant.Params.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false;
return AbilityConstant.OnContinueResult.AGREE;
}
......
......@@ -6,16 +6,16 @@
| onShow?():&nbsp;void; | \@ohos.window.d.ts | [on(eventType:&nbsp;'windowStageEvent',&nbsp;callback:&nbsp;Callback&lt;WindowStageEventType&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#onwindowstageevent9)<br/>监听[FOREGROUND](../reference/apis/js-apis-window.md#windowstageeventtype9)切到前台状态 |
| onHide?():&nbsp;void; | \@ohos.window.d.ts | [on(eventType:&nbsp;'windowStageEvent',&nbsp;callback:&nbsp;Callback&lt;WindowStageEventType&gt;):&nbsp;void;](../reference/apis/js-apis-window.md#onwindowstageevent9)<br/>监听[BACKGROUND](../reference/apis/js-apis-window.md#windowstageeventtype9)切到后台状态 |
| onDestroy?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onDestroy():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityondestroy) |
| onCreate?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) |
| onCreate?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) |
| onWindowDisplayModeChanged?(isShownInMultiWindow:&nbsp;boolean,&nbsp;newConfig:&nbsp;resourceManager.Configuration):&nbsp;void; | Stage模型无对应接口 | 暂时未提供对应接口 |
| onStartContinuation?():&nbsp;boolean; | Stage模型无对应接口 | Stage模型上,应用无需感知迁移是否成功(由应用发起迁移请求时感知),onStartContinuation废弃 |
| onSaveData?(data:&nbsp;Object):&nbsp;boolean; | \@ohos.app.ability.UIAbility.d.ts | [onContinue(wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;AbilityConstant.OnContinueResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) |
| onCompleteContinuation?(result:&nbsp;number):&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onRestoreData?(data:&nbsp;Object):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>[onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br/>多实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例模式应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据 |
| onRestoreData?(data:&nbsp;Object):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>[onNewWant(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br/>多实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例模式应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据 |
| onRemoteTerminated?():&nbsp;void; | application\ContinueCallback.d.ts | [onContinueDone(result:&nbsp;number):&nbsp;void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onSaveAbilityState?(outState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onSaveState(reason:&nbsp;AbilityConstant.StateType,&nbsp;wantParam&nbsp;:&nbsp;{[key:&nbsp;string]:&nbsp;Object}):&nbsp;AbilityConstant.OnSaveResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonsavestate) |
| onRestoreAbilityState?(inState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据 |
| onRestoreAbilityState?(inState:&nbsp;PacMap):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br/>应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据 |
| onInactive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onBackground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonbackground) |
| onActive?():&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onForeground():&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonforeground) |
| onNewWant?(want:&nbsp;Want):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) |
| onNewWant?(want:&nbsp;Want):&nbsp;void; | \@ohos.app.ability.UIAbility.d.ts | [onNewWant(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) |
| onMemoryLevel?(level:&nbsp;number):&nbsp;void | \@ohos.app.ability.UIAbility.d.ts | [onMemoryLevel(level:&nbsp;AbilityConstant.MemoryLevel):&nbsp;void;](../reference/apis/js-apis-app-ability-ability.md#abilityonmemorylevel) |
......@@ -11,11 +11,11 @@ FA模型中PageAbility对应Stage模型中的UIAbility。切换步骤如下。
| FA的PageAbility | Stage的UIAbility | 对应关系描述 |
| -------- | -------- | -------- |
| onCreate():&nbsp;void | onCreate(want:&nbsp;Want,&nbsp;param:&nbsp;AbilityConstant.LaunchParam):&nbsp;void | 两者的意义和调用时机一致,Stage模型在回调中新增了参数,方便开发者在创建的时候获取启动相关的数据。 |
| onCreate():&nbsp;void | onCreate(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void | 两者的意义和调用时机一致,Stage模型在回调中新增了参数,方便开发者在创建的时候获取启动相关的数据。 |
| NA | onWindowStageCreate(windowStage:&nbsp;window.WindowStage):&nbsp;void | Stage模型新增,窗口创建时由系统回调。 |
| onActive():&nbsp;void | on(eventType:&nbsp;'windowStageEvent',&nbsp;callback:&nbsp;Callback&lt;WindowStageEventType&gt;):&nbsp;void;<br/>WindowStageEventType.ACTIVE | 两者的意义和调用时机一致。Stage模型下移动到了窗口对象中。 |
| onShow():&nbsp;void | onForeground():&nbsp;void | 两者的意义和调用时机一致,参数也一致。 |
| onNewWant(want:&nbsp;Want):&nbsp;void | onNewWant(want:&nbsp;Want,&nbsp;launchParams:&nbsp;AbilityConstant.LaunchParam):&nbsp;void | 两者的意义和调用时机一致,Stage模型多了LaunchParam参数来告知应用启动原因。 |
| onNewWant(want:&nbsp;Want):&nbsp;void | onNewWant(want:&nbsp;Want,&nbsp;launchParam:&nbsp;AbilityConstant.LaunchParam):&nbsp;void | 两者的意义和调用时机一致,Stage模型多了LaunchParam参数来告知应用启动原因。 |
| onInactive():&nbsp;void | on(eventType:&nbsp;'windowStageEvent',&nbsp;callback:&nbsp;Callback&lt;WindowStageEventType&gt;):&nbsp;void;<br/>WindowStageEventType.INACTIVE | 两者的意义和调用时机一致。Stage模型下移动到了窗口对象中。 |
| onHide():&nbsp;void | onBackground():&nbsp;void | 两者的意义和调用时机一致,参数也一致。 |
| NA | onWindowStageDestroy():&nbsp;void | Stage模型新增,窗口销毁时由系统回调。 |
......@@ -31,7 +31,7 @@ FA模型中PageAbility对应Stage模型中的UIAbility。切换步骤如下。
例如,开发者希望Ability启动后加载"pages/Index"页面,在FA模型中,开发者需要在config.json中加入如下代码:
```json
"pages" : [
"pages/Index"
......@@ -40,10 +40,10 @@ FA模型中PageAbility对应Stage模型中的UIAbility。切换步骤如下。
在Stage模型中,则在MainAbility中实现如下接口:
```ts
import Window from '@ohos.window'
onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability
windowStage.loadContent('pages/Index', (err, data) => {
......
......@@ -29,7 +29,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
假设应用中有两个UIAbility:EntryAbility和FuncAbility(可以在应用的一个Module中,也可以在的不同Module中),需要从EntryAbility的页面中启动FuncAbility。
1. 在EntryAbility中,通过调用[`startAbility()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability)方法启动UIAbility,[want](../reference/apis/js-apis-app-ability-want.md)为UIAbility实例启动的入口参数,其中bundleName为待启动应用的Bundle名称,abilityName为待启动的Ability名称,moduleName在待启动的UIAbility属于不同的Module时添加,parameters为自定义信息参数。示例中的context的获取方式请参见[获取UIAbility的上下文信息](uiability-usage.md#获取uiability的上下文信息)
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -48,12 +48,12 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
console.error(`Failed to start ability. Code is ${err.code}, message is ${err.message}`);
})
```
2. 在FuncAbility的[`onCreate()`](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityoncreate)或者[`onNewWant()`](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonnewwant)生命周期回调文件中接收EntryAbility传递过来的参数。
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class FuncAbility extends UIAbility {
onCreate(want, launchParam) {
// 接收调用方UIAbility传过来的参数
......@@ -63,16 +63,16 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
}
}
```
> **说明:**
>
> 在被拉起的FuncAbility中,可以通过获取传递过来的`want`参数的`parameters`来获取拉起方UIAbility的PID、Bundle Name等信息。
3. 在FuncAbility业务完成之后,如需要停止当前UIAbility实例,在FuncAbility中通过调用[`terminateSelf()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself)方法实现。
```ts
let context = ...; // UIAbilityContext
// context为需要停止的UIAbility实例的AbilityContext
context.terminateSelf((err) => {
if (err.code) {
......@@ -81,11 +81,11 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
}
});
```
> **说明:**
>
> 调用[`terminateSelf()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself)方法停止当前UIAbility实例时,默认会保留该实例的快照(Snapshot),即在最近任务列表中仍然能查看到该实例对应的任务。如不需要保留该实例的快照,可以在其对应UIAbility的[module.json5配置文件](../quick-start/module-configuration-file.md)中,将[abilities标签](../quick-start/module-configuration-file.md#abilities标签)的removeMissionAfterTerminate字段配置为true。
4. 如需要关闭应用所有的UIAbility实例,可以调用[ApplicationContext](../reference/apis/js-apis-inner-application-applicationContext.md)[`killProcessBySelf()`](../reference/apis/js-apis-inner-application-applicationContext.md#applicationcontextkillallprocesses9)方法实现关闭应用所有的进程。
......@@ -94,7 +94,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
在一个EntryAbility启动另外一个FuncAbility时,希望在被启动的FuncAbility完成相关业务后,能将结果返回给调用方。例如在应用中将入口功能和帐号登录功能分别设计为两个独立的UIAbility,在帐号登录UIAbility中完成登录操作后,需要将登录的结果返回给入口UIAbility。
1. 在EntryAbility中,调用[`startAbilityForResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)接口启动FuncAbility,异步回调中的data用于接收FuncAbility停止自身后返回给EntryAbility的信息。示例中的context的获取方式请参见[获取UIAbility的上下文信息](uiability-usage.md#获取uiability的上下文信息)
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -113,9 +113,9 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
})
```
2. 在FuncAbility停止自身时,需要调用[`terminateSelfWithResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法,入参abilityResult为FuncAbility需要返回给EntryAbility的信息。
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
......@@ -138,15 +138,15 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
}
});
```
3. FuncAbility停止自身后,EntryAbility通过[`startAbilityForResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法回调接收被FuncAbility返回的信息,RESULT_CODE需要与前面的数值保持一致。
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
...
// context为调用方UIAbility的UIAbilityContext
context.startAbilityForResult(want).then((data) => {
if (data?.resultCode === RESULT_CODE) {
......@@ -173,7 +173,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
本文主要讲解如何通过隐式Want启动其他应用的UIAbility。
1. 将多个待匹配的文档应用安装到设备,在其对应UIAbility的[module.json5配置文件](../quick-start/module-configuration-file.md)中,配置skills标签的entities字段和actions字段。
```json
{
"module": {
......@@ -199,7 +199,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
```
2. 在调用方want参数中的entities和action需要被包含在待匹配UIAbility的skills配置的entities和actions中。系统匹配到符合entities和actions参数条件的UIAbility后,会弹出选择框展示匹配到的UIAbility实例列表供用户选择使用。示例中的context的获取方式请参见[获取UIAbility的上下文信息](uiability-usage.md#获取uiability的上下文信息)
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -210,7 +210,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
// entities can be omitted.
entities: ['entity.system.default'],
}
// context为调用方UIAbility的UIAbilityContext
context.startAbility(want).then(() => {
console.info('Succeeded in starting ability.');
......@@ -218,15 +218,15 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
console.error(`Failed to start ability. Code is ${err.code}, message is ${err.message}`);
})
```
效果示意如下图所示,点击“打开PDF文档”时,会弹出选择框供用户选择。
效果示意如下图所示,点击“打开PDF文档”时,会弹出选择框供用户选择。
![](figures/uiability-intra-device-interaction.png)
3. 在文档应用使用完成之后,如需要停止当前UIAbility实例,通过调用[`terminateSelf()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself)方法实现。
```ts
let context = ...; // UIAbilityContext
// context为需要停止的UIAbility实例的AbilityContext
context.terminateSelf((err) => {
if (err.code) {
......@@ -242,7 +242,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
当使用隐式Want启动其他应用的UIAbility并希望获取返回结果时,调用方需要使用[`startAbilityForResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法启动目标UIAbility。例如主应用中需要启动三方支付并获取支付结果。
1. 在支付应用对应UIAbility的[module.json5配置文件](../quick-start/module-configuration-file.md)中,配置skills的entities字段和actions字段。
```json
{
"module": {
......@@ -268,7 +268,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
```
2. 调用方使用[`startAbilityForResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法启动支付应用的UIAbility,在调用方want参数中的entities和action需要被包含在待匹配UIAbility的skills标签配置的entities和actions中。异步回调中的data用于后续接收支付UIAbility停止自身后返回给调用方的信息。系统匹配到符合entities和actions参数条件的UIAbility后,会弹出选择框展示匹配到的UIAbility实例列表供用户选择使用。
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -279,7 +279,7 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
// entities can be omitted.
entities: ['entity.system.default']
}
// context为调用方UIAbility的UIAbilityContext
context.startAbilityForResult(want).then((data) => {
...
......@@ -287,9 +287,9 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
})
```
3. 在支付UIAbility完成支付之后,需要调用[`terminateSelfWithResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法实现停止自身,并将abilityResult参数信息返回给调用方。
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
......@@ -312,17 +312,17 @@ UIAbility是系统调度的最小单元。在设备内的功能模块之间跳
}
});
```
4. 在调用方[`startAbilityForResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)方法回调中接收支付应用返回的信息,RESULT_CODE需要与前面[`terminateSelfWithResult()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult)返回的数值保持一致。
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
let want = {
// Want参数信息
};
// context为调用方UIAbility的UIAbilityContext
context.startAbilityForResult(want).then((data) => {
if (data?.resultCode === RESULT_CODE) {
......@@ -383,7 +383,7 @@ context.startAbility(want, options).then(() => {
})
```
效果示意如下图所示。
效果示意如下图所示。
![](figures/start-uiability-floating-window.png)
## 启动UIAbility的指定页面
......@@ -470,7 +470,7 @@ U->>S: 打开短信应用
S-->>U: 显示短信应用主页
U->>S: 将设备回到桌面界面
S->>S: 短信应用进入后台
U->>C: 打开联系人应用
U->>C: 打开联系人应用
C-->>U: 显示联系人应用界面
U->>C: 点击联系人张三的短信按钮
C->>S: 构造Want启动短信应用
......@@ -486,19 +486,19 @@ S-->>U: 显示给张三发短信的页面
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
import { Router, UIContext } from '@ohos.arkui.UIContext';
export default class EntryAbility extends UIAbility {
funcAbilityWant: Want;
uiContext: UIContext;
...
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
...
let windowClass: window.Window;
windowStage.getMainWindow((err, data) => {
if (err.code) {
......@@ -518,8 +518,8 @@ S-->>U: 显示给张三发短信的页面
export default class EntryAbility extends UIAbility {
funcAbilityWant: Want;
uiContext: UIContext;
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam) {
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
if (want?.parameters?.router && want.parameters.router === 'funcA') {
let funcAUrl = 'pages/Second';
let router: Router = this.uiContext.getRouter();
......@@ -530,7 +530,7 @@ S-->>U: 显示给张三发短信的页面
})
}
}
...
}
```
......@@ -568,8 +568,8 @@ Call调用的使用场景主要包括:
Call调用示意图如下所示。
**图1** Call调用示意图
![call](figures/call.png)
**图1** Call调用示意图
![call](figures/call.png)
- CallerAbility调用startAbilityByCall接口获取Caller,并使用Caller对象的call方法向CalleeAbility发送数据。
......@@ -577,9 +577,9 @@ Call调用示意图如下所示。
> **说明:**
> 1. 当前仅支持系统应用使用Call调用。
>
>
> 2. CalleeAbility的启动模式需要为单实例。
>
>
> 3. Call调用既支持本地(设备内)Call调用,也支持跨设备Call调用,下面介绍设备内Call调用方法。跨设备Call调用方法请参见[跨设备Call调用](hop-multi-device-collaboration.md#通过跨设备call调用实现多端协同)。
......@@ -611,11 +611,11 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
在Callee被调用端,需要实现指定方法的数据接收回调函数、数据的序列化及反序列化方法。在需要接收数据期间,通过on接口注册监听,无需接收数据时通过off接口解除监听。
1. 配置UIAbility的启动模式。
例如将CalleeAbility配置为单实例模式`singleton`,配置方式请参见[UIAbility组件启动模式](uiability-launch-type.md)
2. 导入UIAbility模块。
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
```
......@@ -623,23 +623,23 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
3. 定义约定的序列化数据。
调用端及被调用端发送接收的数据格式需协商一致,如下示例约定数据由number和string组成。
```ts
export default class MyParcelable {
num: number = 0;
str: string = '';
constructor(num, string) {
this.num = num;
this.str = string;
}
marshalling(messageSequence) {
messageSequence.writeInt(this.num);
messageSequence.writeString(this.str);
return true;
}
unmarshalling(messageSequence) {
this.num = messageSequence.readInt();
this.str = messageSequence.readString();
......@@ -649,27 +649,27 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
```
4. 实现Callee.on监听及Callee.off解除监听。
被调用端Callee的监听函数注册时机,取决于应用开发者。注册监听之前的数据不会被处理,取消监听之后的数据不会被处理。如下示例在UIAbility的onCreate注册'MSG_SEND_METHOD'监听,在onDestroy取消监听,收到序列化数据后作相应处理并返回,应用开发者根据实际需要做相应处理。具体示例代码如下:
```ts
const TAG: string = '[CalleeAbility]';
const MSG_SEND_METHOD: string = 'CallSendMsg';
function sendMsgCallback(data) {
console.info('CalleeSortFunc called');
// 获取Caller发送的序列化数据
let receivedData = new MyParcelable(0, '');
data.readParcelable(receivedData);
console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`);
// 作相应处理
// 返回序列化数据result给Caller
return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`);
}
export default class CalleeAbility extends UIAbility {
onCreate(want, launchParam) {
try {
......@@ -678,7 +678,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
console.error(`Failed to register. Code is ${err.code}, message is ${err.message}`);
}
}
onDestroy() {
try {
this.callee.off(MSG_SEND_METHOD);
......@@ -693,7 +693,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
### 开发步骤(访问Callee被调用端)
1. 导入UIAbility模块。
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
```
......@@ -701,7 +701,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
2. 获取Caller通信接口。
UIAbilityContext属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取UIAbility实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease监听。应用开发者根据实际需要做相应处理。
```ts
// 注册caller的release监听
private regOnRelease(caller) {
......@@ -714,7 +714,7 @@ Call功能主要接口如下表所示。具体的API详见[接口文档](../refe
console.err(`Failed to caller register on release. Code is ${err.code}, message is ${err.message}`);
}
}
async onButtonGetCaller() {
try {
this.caller = await context.startAbilityByCall({
......
......@@ -6,8 +6,8 @@ UIAbility是包含UI界面的应用组件,提供组件创建、销毁、前后
- [Callee](#callee):UIAbility的内部对象,CalleeAbility(被调用者)可以通过Callee与Caller进行通信。
> **说明:**
>
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块接口仅可在Stage模型下使用。
## 导入模块
......@@ -29,7 +29,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
## UIAbility.onCreate
onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;
UIAbility创建时回调,执行初始化业务逻辑操作。
......@@ -46,7 +46,7 @@ UIAbility创建时回调,执行初始化业务逻辑操作。
```ts
class MyUIAbility extends UIAbility {
onCreate(want, param) {
onCreate(want, launchParam) {
console.log('onCreate, want: ${want.abilityName}');
}
}
......@@ -68,7 +68,7 @@ onWindowStageCreate(windowStage: window.WindowStage): void
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | WindowStage相关信息。 |
**示例:**
```ts
class MyUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
......@@ -87,7 +87,7 @@ onWindowStageDestroy(): void
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:**
```ts
class MyUIAbility extends UIAbility {
onWindowStageDestroy() {
......@@ -112,7 +112,7 @@ onWindowStageRestore(windowStage: window.WindowStage): void
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | WindowStage相关信息。 |
**示例:**
```ts
class MyUIAbility extends UIAbility {
onWindowStageRestore(windowStage) {
......@@ -131,7 +131,7 @@ UIAbility生命周期回调,在销毁时回调,执行资源清理等操作
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:**
```ts
class MyUIAbility extends UIAbility {
......@@ -161,7 +161,7 @@ UIAbility生命周期回调,当应用从后台转到前台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:**
```ts
class MyUIAbility extends UIAbility {
onForeground() {
......@@ -180,7 +180,7 @@ UIAbility生命周期回调,当应用从前台转到后台时触发。
**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
**示例:**
```ts
class MyUIAbility extends UIAbility {
onBackground() {
......@@ -211,7 +211,7 @@ onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResu
| [AbilityConstant.OnContinueResult](js-apis-app-ability-abilityConstant.md#abilityconstantoncontinueresult) | 继续的结果。 |
**示例:**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
......@@ -226,7 +226,7 @@ onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResu
## UIAbility.onNewWant
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;
当传入新的Want,ability再次被拉起时会回调执行该方法。
......@@ -237,15 +237,15 @@ onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-app-ability-want.md) | 是 | Want类型参数,如ability名称,包名等。 |
| launchParams | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | UIAbility启动的原因、上次异常退出的原因信息。 |
| launchParam | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | UIAbility启动的原因、上次异常退出的原因信息。 |
**示例:**
```ts
class MyUIAbility extends UIAbility {
onNewWant(want, launchParams) {
onNewWant(want, launchParam) {
console.log('onNewWant, want: ${want.abilityName}');
console.log('onNewWant, launchParams: ${JSON.stringify(launchParams)}');
console.log('onNewWant, launchParam: ${JSON.stringify(launchParam)}');
}
}
```
......@@ -265,7 +265,7 @@ onDump(params: Array\<string>): Array\<string>;
| params | Array\<string> | 是 | 表示命令形式的参数。|
**示例:**
```ts
class MyUIAbility extends UIAbility {
onDump(params) {
......@@ -326,7 +326,7 @@ ability设置分享数据,ohos.extra.param.key.shareUrl表示服务的在线
| wantParam | {[key:&nbsp;string]:&nbsp;Object} | 是 | want相关参数。 |
**示例:**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
......@@ -419,7 +419,7 @@ call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;;
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
class MyMessageAble{ // 自定义的Parcelable数据结构
name:''
......@@ -569,7 +569,7 @@ release(): void;
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -615,7 +615,7 @@ release(): void;
| callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回onRelease回调结果。 |
**示例:**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -663,7 +663,7 @@ onRemoteStateChange(callback: OnRemoteStateChangeCallback): void;
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
......@@ -717,7 +717,7 @@ on(type: 'release', callback: OnReleaseCallback): void;
以上错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md)
**示例:**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -764,7 +764,7 @@ off(type: 'release', callback: OnReleaseCallback): void;
| 401 | If the input parameter is not valid parameter. |
**示例:**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -806,7 +806,7 @@ off(type: 'release'): void;
| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
**示例:**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -823,7 +823,7 @@ off(type: 'release'): void;
};
caller.on('release', onReleaseCallBack);
caller.off('release');
} catch (error) {
} catch (error) {
console.error('Caller.on or Caller.off catch error, error.code: ${error.code}, error.message: ${error.message}');
}
}).catch((err) => {
......@@ -929,7 +929,7 @@ off(method: string): void;
**示例:**
```ts
let method = 'call_Function';
export default class MainUIAbility extends UIAbility {
......
......@@ -257,7 +257,7 @@
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: launchWant: Want;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: lastRequestWant: Want;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: callee: Callee;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onCreate(want: Want, param: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onWindowStageCreate(windowStage: window.WindowStage): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onWindowStageDestroy(): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onWindowStageRestore(windowStage: window.WindowStage): void;|@ohos.app.ability.UIAbility.d.ts|
......@@ -265,7 +265,7 @@
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onForeground(): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onBackground(): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResult;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onDump(params: Array\<string>): Array\<string>;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.UIAbility<br>类名: UIAbility<br>方法 or 属性: onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;|@ohos.app.ability.UIAbility.d.ts|
|新增|NA|模块名: ohos.app.ability.Want<br>类名: Want|@ohos.app.ability.Want.d.ts|
......
......@@ -73,5 +73,5 @@ OpenHarmony 3.2 Beta2版本相较于OpenHarmony 3.2 Beta1版本,元能力子
| FormExtensionContext | FormExtensionContext | updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void;<br>updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>; | 删除 |
| ServiceExtensionContext | ServiceExtensionContext | extensionAbilityInfo: ExtensionAbilityInfo; | 删除 |
| ohos.application.appManager | appManager | getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;<br>getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void; | 废弃 |
| ohos.application.Ability | Ability | old : onNewWant(want: Want): void;<br>new : onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | 变更 |
| ohos.application.Ability | Ability | old : onNewWant(want: Want): void;<br>new : onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void; | 变更 |
| ohos.application.Ability | Callee | old : on(method: string, callback: CaleeCallBack): void;<br>new : on(method: string, callback: CalleeCallBack): void; | 变更 |
\ No newline at end of file
......@@ -24,7 +24,7 @@
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:launchWant: Want;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:lastRequestWant: Want;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:callee: Callee;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onCreate(want: Want, param: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onWindowStageCreate(windowStage: window.WindowStage): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onWindowStageDestroy(): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onWindowStageRestore(windowStage: window.WindowStage): void;|NA|@ohos.application.Ability.d.ts|
......@@ -32,7 +32,7 @@
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onForeground(): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onBackground(): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onConfigurationUpdated(config: Configuration): void;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:dump(params: Array<string>): Array<string>;|NA|@ohos.application.Ability.d.ts|
|删除|模块名: ohos.application.Ability<br>类名: Ability<br>方法 or 属性:onMemoryLevel(level: AbilityConstant.MemoryLevel): void;|NA|@ohos.application.Ability.d.ts|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册