提交 084062a0 编写于 作者: G Gloria

Update docs against 22255+22190

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 756132ba
# Multi-device Collaboration (for System Applications Only)
# Multi-device Collaboration
## When to Use
......@@ -57,29 +57,31 @@ On device A, touch the **Start** button provided by the initiator application to
3. Obtain the device ID of the target device.
```ts
import deviceManager from '@ohos.distributedHardware.deviceManager';
import deviceManager from '@ohos.distributedDeviceManager';
let dmClass;
let dmClass: deviceManager.DeviceManager;
function initDmClass() {
// createDeviceManager is a system API.
deviceManager.createDeviceManager('ohos.samples.demo', (err, dm) => {
if (err) {
...
return
}
dmClass = dm
})
try{
dmClass = deviceManager.createDeviceManager('ohos.samples.demo');
} catch(err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
}
}
function getRemoteDeviceId() {
if (typeof dmClass === 'object' && dmClass !== null) {
let list = dmClass.getTrustedDeviceListSync()
let list = dmClass.getAvailableDeviceListSync();
if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') {
console.info('EntryAbility onButtonClick getRemoteDeviceId err: list is null')
console.info('getRemoteDeviceId err: list is null');
return;
}
if (list.length === 0) {
console.info("getRemoteDeviceId err: list is empty");
return;
}
return list[0].deviceId
return list[0].networkId;
} else {
console.info('EntryAbility onButtonClick getRemoteDeviceId err: dmClass is null')
console.info('getRemoteDeviceId err: dmClass is null');
}
}
```
......@@ -90,8 +92,8 @@ On device A, touch the **Start** button provided by the initiator application to
let want = {
deviceId: getRemoteDeviceId(),
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'module1', // moduleName is optional.
abilityName: 'EntryAbility',
moduleName: 'entry', // moduleName is optional.
}
// context is the AbilityContext of the initiator UIAbility.
this.context.startAbility(want).then(() => {
......@@ -217,7 +219,7 @@ A system application can connect to a service on another device by calling [conn
2. Display a dialog box to ask for authorization from the user when the application is started for the first time. For details, see [Requesting User Authorization](../security/accesstoken-guidelines.md#requesting-user-authorization).
3. (Optional) [Implement a background service](serviceextensionability.md#implementing-a-background-service). Perform this operation only if no background service is available.
3. (Optional) [Implement a background service](serviceextensionability.md#implementing-a-background-service-for-system-applications-only). Perform this operation only if no background service is available.
4. Connect to the background service.
- Implement the **IAbilityConnection** class. **IAbilityConnection** provides the following callbacks that you should implement: **onConnect()**, **onDisconnect()**, and **onFailed()**. The **onConnect()** callback is invoked when a service is connected, **onDisconnect()** is invoked when a service is unexpectedly disconnected, and **onFailed()** is invoked when the connection to a service fails.
......@@ -477,8 +479,8 @@ The following describes how to implement multi-device collaboration through cros
```ts
const MSG_SEND_METHOD: string = 'CallSendMsg';
originMsg: string = '';
backMsg: string = '';
let originMsg: string = '';
let backMsg: string = '';
async onButtonCallWithResult(originMsg, backMsg) {
try {
let msg = new MyParcelable(1, originMsg);
......
......@@ -20,12 +20,15 @@ In OpenHarmony, distributed operations across devices are called continuation (a
- **Multi-device collaboration**
Multi-device collaboration provides users with more efficient and immersive experience than with a single device. A typical multi-device collaboration scenario is as follows: You open the same note on devices A and B. On device A, you select images from the local Gallery, insert them to the note, and edit them. On device B, you edit the text. Another typical scenario is as follows: You are chatting with a customer on device A, and the customer asks for a file, which is stored on device B. You can use the chat software to open the file application on device B, select the required file, and send it back to device A. Then, you use the chat software to send it to the customer. From the perspective of application development, multi-device collaboration enables different UIAbility or ServiceExtensionAbility components to run simultaneously or alternately on multiple devices to provide a complete service, or enables the same UIAbility and ServiceExtensionAbility component to run simultaneously on multiple devices to provide a complete service.
Multi-device collaboration provides users with more efficient and immersive experience than with a single device. Multi-device collaboration is used in the following typical scenarios:
- Scenario 1: You open the same note on devices A and B. On device A, you select images from the local Gallery, insert them to the note, and edit them. On device B, you edit the text.
- Scenario 2: : You are chatting with a customer on device A, and the customer asks for a file, which is stored on device B. You can use the chat software to open the file application on device B, select the required file, and send it back to device A. Then, you use the chat software to send it to the customer. From the perspective of application development, multi-device collaboration enables different UIAbility or ServiceExtensionAbility components to run simultaneously or alternately on multiple devices to provide a complete service, or enables the same UIAbility and ServiceExtensionAbility component to run simultaneously on multiple devices to provide a complete service.
## Continuation Architecture
OpenHarmony provides a set of APIs for you to implement continuation in your applications. The continuation architecture has the following advantages:
OpenHarmony provides APIs for you to implement continuation in your applications. The continuation architecture has the following advantages:
- Capabilities such as remote service invocation to facilitate service design
......@@ -39,9 +42,9 @@ The following figure shows the continuation architecture.
![hop-structure](figures/hop-structure.png)
- Cross-device migration mission management: The initiator accepts a migration request from the user, provides a migration entry, and displays the migration result. (This capability is unavailable yet.)
- Cross-device migration mission management: The initiator accepts a migration request from the user, provides a migration entry, and displays the migration result.
- Multi-device collaboration mission management: The initiator accepts an application registration request and provides management capabilities such as starting or stopping collaboration and status display. (This capability is unavailable yet.)
- Multi-device collaboration mission management: The initiator accepts an application registration request and provides management capabilities such as starting or stopping collaboration and status display.
- Distributed component management: provides capabilities such as remote service startup, remote service connection, and remote migration, and provides applications with cross-device migration or multi-device collaboration based on a combination of these capabilities.
......
......@@ -6,16 +6,16 @@
| onShow?(): void; | \@ohos.window.d.ts | [on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;](../reference/apis/js-apis-window.md#onwindowstageevent9)<br>Listens for the switching to the [foreground](../reference/apis/js-apis-window.md#windowstageeventtype9).|
| onHide?(): void; | \@ohos.window.d.ts | [on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;](../reference/apis/js-apis-window.md#onwindowstageevent9)<br>Listens for the switching to the [background](../reference/apis/js-apis-window.md#windowstageeventtype9).|
| onDestroy?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onDestroy(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityondestroy) |
| onCreate?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) |
| onCreate?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate) |
| onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void; | There is no corresponding API in the stage model.| No corresponding API is provided.|
| onStartContinuation?(): boolean; | There is no corresponding API in the stage model.| In the stage model, an application does not need to detect whether the continuation is successful (detected when the application initiates the continuation request). Therefore, the **onStartContinuation()** callback is deprecated.|
| onSaveData?(data: Object): boolean; | \@ohos.app.ability.UIAbility.d.ts | [onContinue(wantParam : {[key: string]: Object}): AbilityConstant.OnContinueResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncontinue) |
| onCompleteContinuation?(result: number): void; | application\ContinueCallback.d.ts | [onContinueDone(result: number): void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onRestoreData?(data: Object): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br>[onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br>In multiton or singleton mode, the target ability completes data restoration in the **onCreate()** callback. In the callback, **launchParam.launchReason** is used to determine whether it is a continuation-based launch scenario. If it is, the data saved before continuation can be obtained from the **want** parameter.|
| onRestoreData?(data: Object): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br>[onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant)<br>In multiton or singleton mode, the target ability completes data restoration in the **onCreate()** callback. In the callback, **launchParam.launchReason** is used to determine whether it is a continuation-based launch scenario. If it is, the data saved before continuation can be obtained from the **want** parameter.|
| onRemoteTerminated?(): void; | application\ContinueCallback.d.ts | [onContinueDone(result: number): void;](../reference/apis/js-apis-distributedMissionManager.md#continuecallback) |
| onSaveAbilityState?(outState: PacMap): void; | \@ohos.app.ability.UIAbility.d.ts | [onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonsavestate) |
| onRestoreAbilityState?(inState: PacMap): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, param: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br>After an application is restarted, the **onCreate()** callback is triggered. In the callback, **launchParam.launchReason** is used to determine whether it is a self-recovery scenario. If it is, the data saved before the restart can be obtained from the **want** parameter.|
| onRestoreAbilityState?(inState: PacMap): void; | \@ohos.app.ability.UIAbility.d.ts | [onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityoncreate)<br>After an application is restarted, the **onCreate()** callback is triggered. In the callback, **launchParam.launchReason** is used to determine whether it is a self-recovery scenario. If it is, the data saved before the restart can be obtained from the **want** parameter.|
| onInactive?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onBackground(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonbackground) |
| onActive?(): void; | \@ohos.app.ability.UIAbility.d.ts | [onForeground(): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonforeground) |
| onNewWant?(want: Want): void; | \@ohos.app.ability.UIAbility.d.ts | [onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) |
| onNewWant?(want: Want): void; | \@ohos.app.ability.UIAbility.d.ts | [onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) |
| onMemoryLevel?(level: number): void | \@ohos.app.ability.UIAbility.d.ts | [onMemoryLevel(level: AbilityConstant.MemoryLevel): void;](../reference/apis/js-apis-app-ability-ability.md#abilityonmemorylevel) |
......@@ -8,30 +8,30 @@ The PageAbility component in the FA model corresponds to the UIAbility component
2. Migrate the PageAbility code to the UIAbility.
The PageAbility lifecycle is basically the same as the UIAbility lifecycle. The table below describes the details.
| PageAbility| UIAbility| Mapping Description|
| -------- | -------- | -------- |
| onCreate(): void| onCreate(want: Want, param: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, parameters are added to the callback so that you can obtain startup-related data during creation.|
| NA | onWindowStageCreate(windowStage: window.WindowStage): void| This method is available only in the stage model. The callback is invoked when a window is created.|
| onActive(): void | on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.ACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
| onShow(): void | onForeground(): void | The two methods have the same meaning, invoking time, and parameters.|
| onNewWant(want: Want): void| onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void| The two methods have the same meaning and invoking time. In the stage model, the **LaunchParam** parameter is added to notify the application of the startup cause.|
| onInactive(): void| on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.INACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
| onHide(): void | onBackground(): void | The two methods have the same meaning, invoking time, and parameters.|
| NA | onWindowStageDestroy(): void | This method is available only in the stage model. The callback is invoked when a window is destroyed.|
| PageAbility| UIAbility| Mapping Description|
| -------- | -------- | -------- |
| onCreate(): void| onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, parameters are added to the callback so that you can obtain startup-related data during creation.|
| NA | onWindowStageCreate(windowStage: window.WindowStage): void| This method is available only in the stage model. The callback is invoked when a window is created.|
| onActive(): void | on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.ACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
| onShow(): void | onForeground(): void | The two methods have the same meaning, invoking time, and parameters.|
| onNewWant(want: Want): void| onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void | The two methods have the same meaning and invoking time. In the stage model, the **LaunchParam** parameter is added to notify the application of the startup cause.|
| onInactive(): void| on(eventType: 'windowStageEvent', callback: Callback&lt;WindowStageEventType&gt;): void;<br>WindowStageEventType.INACTIVE | The two methods have the same meaning and invoking time. In the stage model, this method is moved to the window object.|
| onHide(): void | onBackground(): void | The two methods have the same meaning, invoking time, and parameters.|
| NA | onWindowStageDestroy(): void | This method is available only in the stage model. The callback is invoked when a window is destroyed.|
| onDestroy(): void | onDestroy(): void | The two methods have the same meaning, invoking time, and parameters.|
![pageability-switch](figures/pageability-switch.png)
3. Adjust the migrated code, since the methods of loading pages are different.
- In the FA model, you can configure the page to be loaded by setting page information in **config.json**.
- In the stage model, call **windowStage.loadContent** in the **onWindowStageCreate** callback to load a page.
For example, to load the **pages/Index** page after the ability is started, use the following code in the **config.json** file in the FA model:
```json
"pages" : [
"pages/Index"
......@@ -39,8 +39,7 @@ The PageAbility lifecycle is basically the same as the UIAbility lifecycle. The
```
In the stage model, implement the following method in **MainAbility**:
```ts
import Window from '@ohos.window'
......@@ -53,4 +52,4 @@ The PageAbility lifecycle is basically the same as the UIAbility lifecycle. The
}
});
}
```
```
\ No newline at end of file
......@@ -29,7 +29,7 @@ This scenario is possible when an application contains multiple UIAbility compon
Assume that your application has two UIAbility components: EntryAbility and FuncAbility, either in the same module or different modules. To start FuncAbility from EntryAbility, proceed as follows:
1. In EntryAbility, call [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) and pass the [want](../reference/apis/js-apis-app-ability-want.md) parameter to start the UIAbility instance. In the **want** parameter, **bundleName** indicates the bundle name of the application to start; **abilityName** indicates the name of the UIAbility to start; **moduleName** is required only when the target UIAbility belongs to a different module from EntryAbility; **parameters** is used to carry custom information. For details about how to obtain the context in the example, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -48,12 +48,12 @@ Assume that your application has two UIAbility components: EntryAbility and Func
console.error(`Failed to start ability. Code is ${err.code}, message is ${err.message}`);
})
```
2. In FuncAbility, use [onCreate()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityoncreate) or [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#uiabilityonnewwant) to receive the parameters passed in by EntryAbility.
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
export default class FuncAbility extends UIAbility {
onCreate(want, launchParam) {
// Receive the parameters passed by the initiator UIAbility.
......@@ -63,16 +63,16 @@ Assume that your application has two UIAbility components: EntryAbility and Func
}
}
```
> **NOTE**
>
> In FuncAbility started, you can obtain the PID and bundle name of the UIAbility through **parameters** in the passed **want** parameter.
3. To stop the **UIAbility** instance after the FuncAbility service is not needed, call [terminateSelf()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself) in FuncAbility.
```ts
let context = ...; // UIAbilityContext
// context is the UIAbilityContext of the UIAbility instance to stop.
context.terminateSelf((err) => {
if (err.code) {
......@@ -81,11 +81,11 @@ Assume that your application has two UIAbility components: EntryAbility and Func
}
});
```
> **NOTE**
>
> When [terminateSelf()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself) is called to stop the **UIAbility** instance, the snapshot of the instance is retained by default. That is, the mission corresponding to the instance is still displayed in Recents. If you do not want to retain the snapshot, set **removeMissionAfterTerminate** under the [abilities](../quick-start/module-configuration-file.md#abilities) tag to **true** in the [module.json5 file](../quick-start/module-configuration-file.md) of the corresponding UIAbility.
4. To stop all UIAbility instances of the application, call [killProcessBySelf()](../reference/apis/js-apis-inner-application-applicationContext.md#applicationcontextkillallprocesses9) of [ApplicationContext](../reference/apis/js-apis-inner-application-applicationContext.md).
......@@ -94,7 +94,7 @@ Assume that your application has two UIAbility components: EntryAbility and Func
When starting FuncAbility from EntryAbility, you may want the result to be returned after the FuncAbility service is finished. For example, after the sign-in operation is finished in the sign-in UIAbility of your application, you want the sign-in result to be returned to the entry UIAbility.
1. In EntryAbility, call [startAbilityForResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to start FuncAbility. Use **data** in the asynchronous callback to receive information returned after FuncAbility stops itself. For details about how to obtain the context in the example, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -113,9 +113,9 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur
console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
})
```
2. Call [terminateSelfWithResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to stop FuncAbility. Use the input parameter **abilityResult** to carry the information that FuncAbility needs to return to EntryAbility.
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
......@@ -138,15 +138,15 @@ When starting FuncAbility from EntryAbility, you may want the result to be retur
}
});
```
3. After FuncAbility stops itself, EntryAbility uses [startAbilityForResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to receive the information returned by FuncAbility. The value of **RESULT_CODE** must be the same as that specified in the preceding step.
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
...
// context is the UIAbilityContext of the initiator UIAbility.
context.startAbilityForResult(want).then((data) => {
if (data?.resultCode === RESULT_CODE) {
......@@ -173,7 +173,7 @@ There are two ways to start **UIAbility**: [explicit and implicit](want-overview
The following example describes how to start the UIAbility of another application through implicit Want.
1. Install multiple document applications on your device. In the [module.json5 file](../quick-start/module-configuration-file.md) of each UIAbility component, configure **entities** and **actions** under **skills**.
```json
{
"module": {
......@@ -199,7 +199,7 @@ The following example describes how to start the UIAbility of another applicatio
```
2. Include **entities** and **actions** of the initiator UIAbility's **want** parameter into **entities** and **actions** under **skills** of the target UIAbility. After the system identifies the UIAbility instances that match the **entities** and **actions** information, a dialog box is displayed, showing the list of matching UIAbility instances for users to select. For details about how to obtain the context in the example, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -210,7 +210,7 @@ The following example describes how to start the UIAbility of another applicatio
// entities can be omitted.
entities: ['entity.system.default'],
}
// context is the UIAbilityContext of the initiator UIAbility.
context.startAbility(want).then(() => {
console.info('Succeeded in starting ability.');
......@@ -218,16 +218,16 @@ The following example describes how to start the UIAbility of another applicatio
console.error(`Failed to start ability. Code is ${err.code}, message is ${err.message}`);
})
```
The following figure shows the effect. When you click **Open PDF**, a dialog box is displayed for you to select the application to use.
![](figures/uiability-intra-device-interaction.png)
3. To stop the **UIAbility** instance when the document application is not in use, call [terminateSelf()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself).
```ts
let context = ...; // UIAbilityContext
// context is the UIAbilityContext of the UIAbility instance to stop.
context.terminateSelf((err) => {
if (err.code) {
......@@ -243,7 +243,7 @@ The following example describes how to start the UIAbility of another applicatio
If you want to obtain the return result when using implicit Want to start the UIAbility of another application, use [startAbilityForResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult). An example scenario is that your application needs to start a third-party payment application and obtain the payment result.
1. In the [module.json5 file](../quick-start/module-configuration-file.md) of the UIAbility corresponding to the payment application, set **entities** and **actions** under **skills**.
```json
{
"module": {
......@@ -269,7 +269,7 @@ If you want to obtain the return result when using implicit Want to start the UI
```
2. Call [startAbilityForResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to start the UIAbility of the payment application. Include **entities** and **actions** of the initiator UIAbility's **want** parameter into **entities** and **actions** under **skills** of the target UIAbility. Use **data** in the asynchronous callback to receive the information returned to the initiator UIAbility after the payment UIAbility stops itself. After the system identifies the UIAbility instances that match the **entities** and **actions** information, a dialog box is displayed, showing the list of matching UIAbility instances for users to select.
```ts
let context = ...; // UIAbilityContext
let want = {
......@@ -280,7 +280,7 @@ If you want to obtain the return result when using implicit Want to start the UI
// entities can be omitted.
entities: ['entity.system.default']
}
// context is the UIAbilityContext of the initiator UIAbility.
context.startAbilityForResult(want).then((data) => {
...
......@@ -288,9 +288,9 @@ If you want to obtain the return result when using implicit Want to start the UI
console.error(`Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
})
```
3. After the payment is finished, call [terminateSelfWithResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to stop the payment UIAbility and return the **abilityResult** parameter.
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
......@@ -313,17 +313,17 @@ If you want to obtain the return result when using implicit Want to start the UI
}
});
```
4. Receive the information returned by the payment application in the callback of the [startAbilityForResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) method. The value of **RESULT_CODE** must be the same as that returned by [terminateSelfWithResult()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult).
```ts
let context = ...; // UIAbilityContext
const RESULT_CODE: number = 1001;
let want = {
// Want parameter information.
};
// context is the UIAbilityContext of the initiator UIAbility.
context.startAbilityForResult(want).then((data) => {
if (data?.resultCode === RESULT_CODE) {
......@@ -350,8 +350,8 @@ The window mode is specified by the **windowMode** field in the [StartOptions](.
> **NOTE**
>
> 1. If the **windowMode** field is not specified, the UIAbility is started in the default window mode.
> 2. To ensure that the application can be displayed in the required window mode, check the **supportWindowMode** field under [abilities](../quick-start/module-configuration-file.md#abilities) in the [module.json5 file](../quick-start/module-configuration-file.md) of the UIAbility and make sure the specified window mode is supported.
> - If the **windowMode** field is not specified, the UIAbility is started in the default window mode.
> - To ensure that the application can be displayed in the required window mode, check the **supportWindowMode** field under [abilities](../quick-start/module-configuration-file.md#abilities) in the [module.json5 file](../quick-start/module-configuration-file.md) of the UIAbility and make sure the specified window mode is supported.
The following describes how to start the FuncAbility from the EntryAbility page and display it in floating window mode.
......@@ -472,7 +472,7 @@ U->>S: Open the SMS app.
S-->>U: The home page of the SMS app is displayed.
U->>S: Return to the home screen.
S->>S: The SMS app enters the background.
U->>C: Open the Contacts app.
U->>C: Open the Contacts app.
C-->>U: The page of the Contact app is displayed.
U->>C: Touch the SMS button next to a contact.
C->>S: Start the SMS app with Want.
......@@ -488,19 +488,19 @@ The development procedure is as follows:
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 a main page for this UIAbility.
...
let windowClass: window.Window;
windowStage.getMainWindow((err, data) => {
if (err.code) {
......@@ -520,8 +520,8 @@ The development procedure is as follows:
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();
......@@ -532,7 +532,7 @@ The development procedure is as follows:
})
}
}
...
}
```
......@@ -580,9 +580,9 @@ The following figure shows the call process.
> **NOTE**
> - Currently, only system applications can use the call.
>
>
> - The launch type of the CalleeAbility must be **singleton**.
>
>
> - Both local (intra-device) and cross-device calls are supported. The following describes how to initiate a local call. For details about how to initiate a cross-device call, see [Using Cross-Device Call](hop-multi-device-collaboration.md#using-cross-device-call).
......@@ -614,24 +614,24 @@ The implementation of using the call for UIAbility interaction involves two part
For the CalleeAbility, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use **on()** to register a listener. When data does not need to be received, use **off()** to deregister the listener.
1. Configure the launch type of the CalleeAbility.
For example, set the launch type of the CalleeAbility to **singleton**. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).
2. Import the **UIAbility** module.
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
```
3. Define the agreed parcelable data.
The data formats sent and received by the CallerAbility and CalleeAbility must be consistent. In the following example, the data formats are number and string.
The data formats sent and received by the CallerAbility and CalleeAbility must be consistent. In the following example, the data formats are number and string.
```ts
export default class MyParcelable {
num: number = 0;
str: string = '';
constructor(num, string) {
this.num = num;
this.str = string;
......@@ -650,9 +650,9 @@ For the CalleeAbility, implement the callback to receive data and the methods to
}
}
```
4. Implement **Callee.on** and **Callee.off**.
4. Implement **Callee.on** and **Callee.off**.
The time to register a listener for the CalleeAbility depends on your application. The data sent and received before the listener is registered and that after the listener is deregistered are not processed. In the following example, the **MSG_SEND_METHOD** listener is registered in **onCreate** of the UIAbility and deregistered in **onDestroy**. After receiving parcelable data, the application processes the data and returns the data result. You need to implement processing based on service requirements. The sample code is as follows:
......@@ -696,7 +696,7 @@ For the CalleeAbility, implement the callback to receive data and the methods to
### Accessing the CalleeAbility
1. Import the **UIAbility** module.
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
```
......@@ -735,4 +735,4 @@ For the CalleeAbility, implement the callback to receive data and the methods to
console.err(`Failed to get caller. Code is ${err.code}, message is ${err.message}`);
}
}
```
```
\ No newline at end of file
......@@ -6,8 +6,8 @@ UIAbility is an application component that has the UI. The **UIAbility** module
- [Callee](#callee): an internal object of UIAbility. The CalleeAbility (callee) uses this object to communicate with the CallerAbility (caller).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
## Modules to Import
......@@ -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;
Called to initialize the service logic when a UIAbility is created.
......@@ -46,7 +46,7 @@ Called to initialize the service logic when a UIAbility is created.
```ts
class MyUIAbility extends UIAbility {
onCreate(want, param) {
onCreate(want, launchParam) {
console.log('onCreate, want: ${want.abilityName}');
}
}
......@@ -68,7 +68,7 @@ Called when a **WindowStage** is created for this UIAbility.
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
```ts
class MyUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
......@@ -87,7 +87,7 @@ Called when the **WindowStage** is destroyed for this UIAbility.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
class MyUIAbility extends UIAbility {
onWindowStageDestroy() {
......@@ -112,7 +112,7 @@ Called when the **WindowStage** is restored during the migration of this UIAbili
| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
**Example**
```ts
class MyUIAbility extends UIAbility {
onWindowStageRestore(windowStage) {
......@@ -131,7 +131,7 @@ Called when this UIAbility is destroyed to clear resources.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
class MyUIAbility extends UIAbility {
......@@ -161,7 +161,7 @@ Called when this UIAbility is switched from the background to the foreground.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
class MyUIAbility extends UIAbility {
onForeground() {
......@@ -180,7 +180,7 @@ Called when this UIAbility is switched from the foreground to the background.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Example**
```ts
class MyUIAbility extends UIAbility {
onBackground() {
......@@ -211,7 +211,7 @@ Called to save data during the ability migration preparation process.
| [AbilityConstant.OnContinueResult](js-apis-app-ability-abilityConstant.md#abilityconstantoncontinueresult) | Continuation result.|
**Example**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
......@@ -226,7 +226,7 @@ Called to save data during the ability migration preparation process.
## UIAbility.onNewWant
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;
Called when a new Want is passed in and this UIAbility is started again.
......@@ -237,15 +237,15 @@ Called when a new Want is passed in and this UIAbility is started again.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-app-ability-want.md) | Yes| Want information, such as the ability name and bundle name.|
| launchParams | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Reason for the UIAbility startup and the last abnormal exit.|
| launchParam | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Reason for the UIAbility startup and the last abnormal exit.|
**Example**
```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 @@ Dumps client information.
| params | Array\<string> | Yes| Parameters in the form of a command.|
**Example**
```ts
class MyUIAbility extends UIAbility {
onDump(params) {
......@@ -315,7 +315,7 @@ class MyUIAbility extends UIAbility {
onShare(wantParam:{ [key: string]: Object }): void;
Called by this UIAbility to set data to share. **ohos.extra.param.key.shareUrl** indicates the online address of the service.
Called by this UIAbility to set data to share in the cross-device sharing scenario.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
......@@ -323,10 +323,10 @@ Called by this UIAbility to set data to share. **ohos.extra.param.key.shareUrl**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;Object} | Yes| **want** parameter.|
| wantParam | {[key:&nbsp;string]:&nbsp;Object} | Yes| Data to share.|
**Example**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
......@@ -419,7 +419,7 @@ Sends sequenceable data to the target ability.
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
class MyMessageAble{ // Custom parcelable data structure.
name:''
......@@ -569,7 +569,7 @@ Releases the caller interface of the target ability.
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -615,7 +615,7 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
**Example**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -663,7 +663,7 @@ Registers a callback that is invoked when the remote ability state changes in th
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
......@@ -717,7 +717,7 @@ Registers a callback that is invoked when the stub on the target ability is disc
For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
**Example**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -764,7 +764,7 @@ Deregisters a callback that is invoked when the stub on the target ability is di
| 401 | If the input parameter is not valid parameter. |
**Example**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -806,7 +806,7 @@ Deregisters a callback that is invoked when the stub on the target ability is di
| type | string | Yes| Event type. The value is fixed at **release**.|
**Example**
```ts
let caller;
export default class MainUIAbility extends UIAbility {
......@@ -823,7 +823,7 @@ Deregisters a callback that is invoked when the stub on the target ability is di
};
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 @@ For details about the error codes, see [Ability Error Codes](../errorcodes/error
**Example**
```ts
let method = 'call_Function';
export default class MainUIAbility extends UIAbility {
......
......@@ -257,7 +257,7 @@
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: launchWant: Want;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: lastRequestWant: Want;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: callee: Callee;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onCreate(want: Want, param: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onWindowStageCreate(windowStage: window.WindowStage): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onWindowStageDestroy(): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onWindowStageRestore(windowStage: window.WindowStage): void;|@ohos.app.ability.UIAbility.d.ts|
......@@ -265,7 +265,7 @@
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onForeground(): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onBackground(): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResult;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onDump(params: Array\<string>): Array\<string>;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.UIAbility<br>Class name: UIAbility<br>Method or attribute name: onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;|@ohos.app.ability.UIAbility.d.ts|
|Added|NA|Module name: ohos.app.ability.Want<br>Class name: Want|@ohos.app.ability.Want.d.ts|
......
......@@ -73,5 +73,5 @@ The table below lists the APIs changes of the ability framework in OpenHarmony 3
| FormExtensionContext | FormExtensionContext | updateForm(formId: string, formBindingData: formBindingData.FormBindingData, callback: AsyncCallback\<void>): void;<br>updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise\<void>; | Deleted|
| ServiceExtensionContext | ServiceExtensionContext | extensionAbilityInfo: ExtensionAbilityInfo; | Deleted|
| ohos.application.appManager | appManager | getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;<br>getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void; | Deprecated|
| ohos.application.Ability | Ability | old : onNewWant(want: Want): void;<br>new : onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void; | Updated|
| ohos.application.Ability | Callee | old : on(method: string, callback: CaleeCallBack): void;<br>new : on(method: string, callback: CalleeCallBack): void; | Updated|
| ohos.application.Ability | Ability | old : onNewWant(want: Want): void;<br>new : onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void; | Updated|
| ohos.application.Ability | Callee | old : on(method: string, callback: CaleeCallBack): void;<br>new : on(method: string, callback: CalleeCallBack): void; | Updated|
\ No newline at end of file
| Change Type | Old Version | New Version | d.ts File |
| Change Type | Old Version | New Version | .d.ts File |
| ---- | ------ | ------ | -------- |
|Added|NA|Module name: ohos.app.ability.dataUriUtils<br>Class name: dataUriUtils|@ohos.app.ability.dataUriUtils.d.ts|
|Added|NA|Module name: ohos.app.ability.dataUriUtils<br>Class name: dataUriUtils<br>Method or attribute name: function getId(uri: string): number|@ohos.app.ability.dataUriUtils.d.ts|
......@@ -24,7 +24,7 @@
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: launchWant: Want;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: lastRequestWant: Want;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: callee: Callee;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onCreate(want: Want, param: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onWindowStageCreate(windowStage: window.WindowStage): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onWindowStageDestroy(): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onWindowStageRestore(windowStage: window.WindowStage): void;|NA|@ohos.application.Ability.d.ts|
......@@ -32,7 +32,7 @@
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onForeground(): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onBackground(): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: onConfigurationUpdated(config: Configuration): void;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: dump(params: Array<string>): Array<string>;|NA|@ohos.application.Ability.d.ts|
|Deleted|Module name: ohos.application.Ability<br>Class name: Ability<br>Method or attribute name: 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.
先完成此消息的编辑!
想要评论请 注册