• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Intra-Device Interaction Between UIAbility Components
2
3
4UIAbility is the minimum unit that can be scheduled by the system. Jumping between functional modules in a device involves starting of specific UIAbility components, which belong to the same or a different application (for example, starting UIAbility of a third-party payment application).
5
6
7This topic describes the UIAbility interaction modes in the following scenarios. For details about cross-device application component interaction, see [Inter-Device Application Component Interaction (Continuation)](inter-device-interaction-hop-overview.md).
8
9
10- [Starting UIAbility in the Same Application](#starting-uiability-in-the-same-application)
11
12- [Starting UIAbility in the Same Application and Obtaining the Return Result](#starting-uiability-in-the-same-application-and-obtaining-the-return-result)
13
14- [Starting UIAbility of Another Application](#starting-uiability-of-another-application)
15
16- [Starting UIAbility of Another Application and Obtaining the Return Result](#starting-uiability-of-another-application-and-obtaining-the-return-result)
17
18- [Starting a Specified Page of UIAbility](#starting-a-specified-page-of-uiability)
19
20- [Using Call to Implement UIAbility Interaction (for System Applications Only)](#using-call-to-implement-uiability-interaction-for-system-applications-only)
21
22
23## Starting UIAbility in the Same Application
24
25This scenario is possible when an application contains multiple UIAbility components. For example, in a payment application, you may need to start the payment UIAbility from the entry UIAbility.
26
27Assume that your application has two UIAbility components: EntryAbility and FuncAbility, either in the same module or different modules. You are required to start FuncAbility from EntryAbility.
28
291. In EntryAbility, call **startAbility()** to start UIAbility. The [want](../reference/apis/js-apis-app-ability-want.md) parameter is the entry parameter for starting 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; **parameters** is used to carry custom information. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
30
31   ```ts
32   let wantInfo = {
33       deviceId: '', // An empty deviceId indicates the local device.
34       bundleName: 'com.example.myapplication',
35       abilityName: 'FuncAbility',
36       moduleName: 'module1', // moduleName is optional.
37       parameters: {// Custom information.
38           info: 'From the Index page of EntryAbility',
39       },
40   }
41   // context is the AbilityContext of the initiator UIAbility.
42   this.context.startAbility(wantInfo).then(() => {
43       // ...
44   }).catch((err) => {
45       // ...
46   })
47   ```
48
492. Use the FuncAbility lifecycle callback to receive the parameters passed from EntryAbility.
50
51   ```ts
52   import UIAbility from '@ohos.app.ability.UIAbility';
53   import Window from '@ohos.window';
54
55   export default class FuncAbility extends UIAbility {
56       onCreate(want, launchParam) {
57   	// Receive the parameters passed by the initiator UIAbility.
58           let funcAbilityWant = want;
59           let info = funcAbilityWant?.parameters?.info;
60           // ...
61       }
62   }
63   ```
64
653. To stop the **UIAbility** instance after the FuncAbility service is complete, call **terminateSelf()** in FuncAbility.
66
67   ```ts
68   // context is the AbilityContext of the UIAbility instance to stop.
69   this.context.terminateSelf((err) => {
70       // ...
71   });
72   ```
73
74
75## Starting UIAbility in the Same Application and Obtaining the Return Result
76
77When starting FuncAbility from EntryAbility, you want the result to be returned after the FuncAbility service is finished. For example, your application uses two independent UIAbility components to carry the entry and sign-in functionalities. After the sign-in operation is finished in the sign-in UIAbility, the sign-in result needs to be returned to the entry UIAbility.
78
791. In EntryAbility, call **startAbilityForResult()** 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, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
80
81   ```ts
82   let wantInfo = {
83       deviceId: '', // An empty deviceId indicates the local device.
84       bundleName: 'com.example.myapplication',
85       abilityName: 'FuncAbility',
86       moduleName: 'module1', // moduleName is optional.
87       parameters: {// Custom information.
88           info: 'From the Index page of EntryAbility',
89       },
90   }
91   // context is the AbilityContext of the initiator UIAbility.
92   this.context.startAbilityForResult(wantInfo).then((data) => {
93       // ...
94   }).catch((err) => {
95       // ...
96   })
97   ```
98
992. Call **terminateSelfWithResult()** to stop FuncAbility. Use the input parameter **abilityResult** to carry the information that FuncAbility needs to return to EntryAbility.
100
101   ```ts
102   const RESULT_CODE: number = 1001;
103   let abilityResult = {
104       resultCode: RESULT_CODE,
105       want: {
106           bundleName: 'com.example.myapplication',
107           abilityName: 'FuncAbility',
108           moduleName: 'module1',
109           parameters: {
110               info: 'From the Index page of FuncAbility',
111           },
112       },
113   }
114   // context is the AbilityContext of the target UIAbility.
115   this.context.terminateSelfWithResult(abilityResult, (err) => {
116       // ...
117   });
118   ```
119
1203. After FuncAbility stops itself, EntryAbility uses **startAbilityForResult()** to receive the information returned by FuncAbility. The value of **RESULT_CODE** must be the same as the preceding value.
121
122   ```ts
123   const RESULT_CODE: number = 1001;
124
125   // ...
126
127   // context is the AbilityContext of the initiator UIAbility.
128   this.context.startAbilityForResult(want).then((data) => {
129       if (data?.resultCode === RESULT_CODE) {
130           // Parse the information returned by the target UIAbility.
131           let info = data.want?.parameters?.info;
132           // ...
133       }
134   }).catch((err) => {
135       // ...
136   })
137   ```
138
139
140## Starting UIAbility of Another Application
141
142Generally, the user only needs to do a common operation (for example, selecting a document application to view the document content) to start the UIAbility of another application. The [implicit Want launch mode](want-overview.md#types-of-want) is recommended. The system identifies a matched UIAbility and starts it based on the **want** parameter of the initiator UIAbility.
143
144There are two ways to start **UIAbility**: [explicit and implicit](want-overview.md).
145
146- Explicit Want launch: This mode is used to start a determined UIAbility component of an application. You need to set **bundleName** and **abilityName** of the target application in the **want** parameter.
147
148- Implicit Want launch: The user selects a UIAbility to start based on the matching conditions. That is, the UIAbility to start is not determined (the **abilityName** parameter is not specified). When **startAbility()** is called, the **want** parameter specifies a series of parameters such as [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction). **entities** provides category information of the target UIAbility, such as the browser or video player. **actions** specifies the common operations to perform, such as viewing, sharing, and application details. Then the system analyzes the **want** parameter to find the right UIAbility to start. You usually do not know whether the target application is installed and what **bundleName** and **abilityName** of the target application are. Therefore, implicit Want launch is usually used to start the UIAbility of another application.
149
150This section describes how to start the UIAbility of another application through implicit Want.
151
1521. Install multiple document applications on your device. In the **module.json5** file of each UIAbility component, configure [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) under **skills**.
153
154   ```json
155   {
156     "module": {
157       "abilities": [
158         {
159           // ...
160           "skills": [
161             {
162               "entities": [
163                 // ...
164                 "entity.system.default"
165               ],
166               "actions": [
167                 // ...
168                 "ohos.want.action.viewData"
169               ]
170             }
171           ]
172         }
173       ]
174     }
175   }
176   ```
177
1782. Include **entities** and **actions** of the initiator UIAbility's **want** parameter into **entities** and **actions** under **skills** of the target UIAbility. After the system matches the UIAbility that meets the **entities** and **actions** information, a dialog box is displayed, showing the list of matched UIAbility instances for users to select. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
179
180   ```ts
181   let wantInfo = {
182       deviceId: '', // An empty deviceId indicates the local device.
183       // Uncomment the line below if you want to implicitly query data only in the specific bundle.
184       // bundleName: 'com.example.myapplication',
185       action: 'ohos.want.action.viewData',
186       // entities can be omitted.
187       entities: ['entity.system.default'],
188   }
189
190   // context is the AbilityContext of the initiator UIAbility.
191   this.context.startAbility(wantInfo).then(() => {
192       // ...
193   }).catch((err) => {
194       // ...
195   })
196   ```
197
198   The following figure shows the effect. When you click **Open PDF**, a dialog box is displayed for you to select.
199
200   ![uiability-intra-device-interaction](figures/uiability-intra-device-interaction.png)
201
2023. To stop the **UIAbility** instance after the document application is used, call **terminateSelf()**.
203
204   ```ts
205   // context is the AbilityContext of the UIAbility instance to stop.
206   this.context.terminateSelf((err) => {
207       // ...
208   });
209   ```
210
211
212## Starting UIAbility of Another Application and Obtaining the Return Result
213
214If you want to obtain the return result when using implicit Want to start the UIAbility of another application, use **startAbilityForResult()**. An example scenario is that the main application needs to start a third-party payment application and obtain the payment result.
215
2161. In the **module.json5** file of the UIAbility corresponding to the payment application, set [entities](../reference/apis/js-apis-ability-wantConstant.md#wantconstantentity) and [actions](../reference/apis/js-apis-ability-wantConstant.md#wantconstantaction) under **skills**.
217
218   ```json
219   {
220     "module": {
221       "abilities": [
222         {
223           // ...
224           "skills": [
225             {
226               "entities": [
227                 // ...
228                 "entity.system.default"
229               ],
230               "actions": [
231                 // ...
232                 "ohos.want.action.editData"
233               ]
234             }
235           ]
236         }
237       ]
238     }
239   }
240   ```
241
2422. Call **startAbilityForResult()** 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 matches the UIAbility that meets the **entities** and **actions** information, a dialog box is displayed, showing the list of matched UIAbility instances for users to select.
243
244   ```ts
245   let wantInfo = {
246       deviceId: '', // An empty deviceId indicates the local device.
247       // Uncomment the line below if you want to implicitly query data only in the specific bundle.
248       // bundleName: 'com.example.myapplication',
249       action: 'ohos.want.action.editData',
250       // entities can be omitted.
251       entities: ['entity.system.default'],
252   }
253
254   // context is the AbilityContext of the initiator UIAbility.
255   this.context.startAbilityForResult(wantInfo).then((data) => {
256       // ...
257   }).catch((err) => {
258       // ...
259   })
260   ```
261
2623. After the payment is finished, call **terminateSelfWithResult()** to stop the payment UIAbility and return the **abilityResult** parameter.
263
264   ```ts
265   const RESULT_CODE: number = 1001;
266   let abilityResult = {
267       resultCode: RESULT_CODE,
268       want: {
269           bundleName: 'com.example.myapplication',
270           abilityName: 'EntryAbility',
271           moduleName: 'entry',
272           parameters: {
273               payResult: 'OKay',
274           },
275       },
276   }
277   // context is the AbilityContext of the target UIAbility.
278   this.context.terminateSelfWithResult(abilityResult, (err) => {
279       // ...
280   });
281   ```
282
2834. Receive the information returned by the payment application in the callback of **startAbilityForResult()**. The value of **RESULT_CODE** must be the same as that returned by **terminateSelfWithResult()**.
284
285   ```ts
286   const RESULT_CODE: number = 1001;
287
288   let want = {
289     // Want parameter information.
290   };
291
292   // context is the AbilityContext of the initiator UIAbility.
293   this.context.startAbilityForResult(want).then((data) => {
294       if (data?.resultCode === RESULT_CODE) {
295           // Parse the information returned by the target UIAbility.
296           let payResult = data.want?.parameters?.payResult;
297           // ...
298       }
299   }).catch((err) => {
300       // ...
301   })
302   ```
303
304
305## Starting a Specified Page of UIAbility
306
307A UIAbility component can have multiple pages. When it is started in different scenarios, different pages can be displayed. For example, when a user jumps from a page of a UIAbility component to another UIAbility, you want to start a specified page of the target UIAbility. This section describes how to specify a startup page and start the specified page when the target UIAbility is started for the first time or when the target UIAbility is not started for the first time.
308
309
310### Specifying a Startup Page
311
312When the initiator UIAbility starts another UIAbility, it usually needs to redirect to a specified page. For example, FuncAbility contains two pages: Index (corresponding to the home page) and Second (corresponding to function A page). You can configure the specified page URL in the **want** parameter by adding a custom parameter to **parameters** in **want**. For details about how to obtain the context, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
313
314
315```ts
316let wantInfo = {
317    deviceId: '', // An empty deviceId indicates the local device.
318    bundleName: 'com.example.myapplication',
319    abilityName: 'FuncAbility',
320    moduleName: 'module1', // moduleName is optional.
321    parameters: {// Custom parameter used to pass the page information.
322        router: 'funcA',
323    },
324}
325// context is the AbilityContext of the initiator UIAbility.
326this.context.startAbility(wantInfo).then(() => {
327    // ...
328}).catch((err) => {
329    // ...
330})
331```
332
333
334### Starting a Page When the Target UIAbility Is Started for the First Time
335
336When the target UIAbility is started for the first time, in the **onWindowStageCreate()** callback of the target UIAbility, parse the **want** parameter passed by EntryAbility to obtain the URL of the page to be loaded, and pass the URL to the **windowStage.loadContent()** method.
337
338
339```ts
340import UIAbility from '@ohos.app.ability.UIAbility'
341import Window from '@ohos.window'
342
343export default class FuncAbility extends UIAbility {
344    funcAbilityWant;
345
346    onCreate(want, launchParam) {
347        // Receive the parameters passed by the initiator UIAbility.
348        this.funcAbilityWant = want;
349    }
350
351    onWindowStageCreate(windowStage: Window.WindowStage) {
352        // Main window is created. Set a main page for this UIAbility.
353        let url = 'pages/Index';
354        if (this.funcAbilityWant?.parameters?.router) {
355            if (this.funcAbilityWant.parameters.router === 'funA') {
356                url = 'pages/Second';
357            }
358        }
359        windowStage.loadContent(url, (err, data) => {
360            // ...
361        });
362    }
363}
364```
365
366
367### Starting a Page When the Target UIAbility Is Not Started for the First Time
368
369You start application A, and its home page is displayed. Then you return to the home screen and start application B. Now you need to start application A again from application B and have a specified page of application A displayed. An example scenario is as follows: When you open the home page of the SMS application and return to the home screen, the SMS application is in the opened state and its home page is displayed. Then you open the home page of the Contacts application, access user A's details page, and touch the SMS icon to send an SMS message to user A. The SMS application is started again and the sending page is displayed.
370
371![uiability_not_first_started](figures/uiability_not_first_started.png)
372
373In summary, when a UIAbility instance of application A has been created and the main page of the UIAbility instance is displayed, you need to start the UIAbility of application A from application B and have a different page displayed.
374
3751. In the target UIAbility, the **Index** page is loaded by default. The UIAbility instance has been created, and the **onNewWant()** callback rather than **onCreate()** and **onWindowStageCreate()** will be invoked. In the **onNewWant()** callback, parse the **want** parameter and bind it to the global variable **globalThis**.
376
377   ```ts
378   import UIAbility from '@ohos.app.ability.UIAbility'
379
380   export default class FuncAbility extends UIAbility {
381       onNewWant(want, launchParam) {
382           // Receive the parameters passed by the initiator UIAbility.
383           globalThis.funcAbilityWant = want;
384           // ...
385       }
386   }
387   ```
388
3892. In FuncAbility, use the router module to implement redirection to the specified page on the **Index** page. Because the **Index** page of FuncAbility is active, the variable will not be declared again and the **aboutToAppear()** callback will not be triggered. Therefore, the page routing functionality can be implemented in the **onPageShow()** callback of the **Index** page.
390
391   ```ts
392   import router from '@ohos.router';
393
394   @Entry
395   @Component
396   struct Index {
397     onPageShow() {
398       let funcAbilityWant = globalThis.funcAbilityWant;
399       let url2 = funcAbilityWant?.parameters?.router;
400       if (url2 && url2 === 'funcA') {
401         router.replaceUrl({
402           url: 'pages/Second',
403         })
404       }
405     }
406
407     // Page display.
408     build() {
409       // ...
410     }
411   }
412   ```
413
414> **NOTE**
415>
416> When the [launch type of the target UIAbility](uiability-launch-type.md) is set to **standard**, a new instance is created each time the target UIAbility is started. In this case, the [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) callback will not be invoked.
417
418
419## Using Call to Implement UIAbility Interaction (for System Applications Only)
420
421Call is an extension of the UIAbility capability. It enables the UIAbility to be invoked by and communicate with external systems. The UIAbility invoked can be either started in the foreground or created and run in the background. You can use the call to implement data sharing between two UIAbility instances (CallerAbility and CalleeAbility) through IPC.
422
423The core API used for the call is **startAbilityByCall**, which differs from **startAbility** in the following ways:
424
425- **startAbilityByCall** supports UIAbility launch in the foreground and background, whereas **startAbility** supports UIAbility launch in the foreground only.
426
427- The CallerAbility can use the caller object returned by **startAbilityByCall** to communicate with the CalleeAbility, but **startAbility** does not provide the communication capability.
428
429Call is usually used in the following scenarios:
430
431- Communicating with the CalleeAbility
432
433- Starting the CalleeAbility in the background
434
435**Table 1** Terms used in the call
436
437| **Term**| Description|
438| -------- | -------- |
439| CallerAbility | UIAbility that triggers the call.|
440| CalleeAbility | UIAbility invoked by the call.|
441| Caller | Object returned by **startAbilityByCall** and used by the CallerAbility to communicate with the CalleeAbility.|
442| Callee | Object held by the CalleeAbility to communicate with the CallerAbility.|
443
444The following figure shows the call process.
445
446  Figure 1 Call process
447
448  ![call](figures/call.png)
449
450- The CallerAbility uses **startAbilityByCall** to obtain a caller object and uses **call()** of the caller object to send data to the CalleeAbility.
451
452- The CalleeAbility, which holds a **Callee** object, uses **on()** of the **Callee** object to register a callback. This callback is invoked when the CalleeAbility receives data from the CallerAbility.
453
454> **NOTE**
455> 1. Currently, only system applications can use the call.
456>
457> 2. The launch type of the CalleeAbility must be **singleton**.
458>
459> 3. 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).
460
461
462### Available APIs
463
464The following table describes the main APIs used for the call. For details, see [AbilityContext](../reference/apis/js-apis-app-ability-uiAbility.md#caller).
465
466  **Table 2** Call APIs
467
468| API| Description|
469| -------- | -------- |
470| startAbilityByCall(want: Want): Promise<Caller> | Starts a UIAbility in the foreground (through the **want** configuration) or background (default) and obtains the caller object for communication with the UIAbility. For details, see [AbilityContext](../reference/apis/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilitybycall) or [ServiceExtensionContext](../reference/apis/js-apis-inner-application-serviceExtensionContext.md#serviceextensioncontextstartabilitybycall).|
471| on(method: string, callback: CalleeCallBack): void | Callback invoked when the CalleeAbility registers a method.|
472| off(method: string): void | Callback invoked when the CalleeAbility deregisters a method.|
473| call(method: string, data: rpc.Parcelable): Promise<void> | Sends agreed parcelable data to the CalleeAbility.|
474| callWithResult(method: string, data: rpc.Parcelable): Promise<rpc.MessageSequence> | Sends agreed parcelable data to the CalleeAbility and obtains the agreed parcelable data returned by the CalleeAbility.|
475| release(): void | Releases the caller object.|
476| on(type: "release", callback: OnReleaseCallback): void | Callback invoked when the caller object is released.|
477
478The implementation of using the call for UIAbility interaction involves two parts.
479
480- [Creating a CalleeAbility](#creating-a-calleeability)
481
482- [Accessing the CalleeAbility](#accessing-the-calleeability)
483
484
485### Creating a CalleeAbility
486
487For 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.
488
4891. Configure the launch type of the UIAbility.
490
491   Set **launchType** of the CalleeAbility to **singleton** in the **module.json5** file.
492
493   | JSON Field| Description|
494   | -------- | -------- |
495   | "launchType" | Ability launch type. Set this parameter to **singleton**.|
496
497   An example of the ability configuration is as follows:
498
499
500   ```json
501   "abilities":[{
502     "name": ".CalleeAbility",
503     "srcEnty": "./ets/CalleeAbility/CalleeAbility.ts",
504     "launchType": "singleton",
505     "description": "$string:CalleeAbility_desc",
506     "icon": "$media:icon",
507     "label": "$string:CalleeAbility_label",
508     "exported": true
509   }]
510   ```
511
5122. Import the **UIAbility** module.
513
514   ```ts
515   import Ability from '@ohos.app.ability.UIAbility';
516   ```
517
5183. Define the agreed parcelable data.
519
520   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.
521
522
523   ```ts
524   export default class MyParcelable {
525       num: number = 0
526       str: string = ""
527
528       constructor(num, string) {
529           this.num = num
530           this.str = string
531       }
532
533       marshalling(messageSequence) {
534           messageSequence.writeInt(this.num)
535           messageSequence.writeString(this.str)
536           return true
537       }
538
539       unmarshalling(messageSequence) {
540           this.num = messageSequence.readInt()
541           this.str = messageSequence.readString()
542           return true
543       }
544   }
545   ```
546
5474. Implement **Callee.on** and **Callee.off**.
548
549   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:
550
551
552   ```ts
553   const TAG: string = '[CalleeAbility]';
554   const MSG_SEND_METHOD: string = 'CallSendMsg';
555
556   function sendMsgCallback(data) {
557       console.info('CalleeSortFunc called');
558
559       // Obtain the parcelable data sent by the CallerAbility.
560       let receivedData = new MyParcelable(0, '');
561       data.readParcelable(receivedData);
562       console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`);
563
564       // Process the data.
565       // Return the parcelable data result to the CallerAbility.
566       return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`);
567   }
568
569   export default class CalleeAbility extends Ability {
570       onCreate(want, launchParam) {
571           try {
572               this.callee.on(MSG_SEND_METHOD, sendMsgCallback);
573           } catch (error) {
574               console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`);
575           }
576       }
577
578       onDestroy() {
579           try {
580               this.callee.off(MSG_SEND_METHOD);
581           } catch (error) {
582               console.error(TAG, `${MSG_SEND_METHOD} unregister failed with error ${JSON.stringify(error)}`);
583           }
584       }
585   }
586   ```
587
588
589### Accessing the CalleeAbility
590
5911. Import the **UIAbility** module.
592
593   ```ts
594   import Ability from '@ohos.app.ability.UIAbility';
595   ```
596
5972. Obtain the caller interface.
598
599   The **context** attribute of the UIAbility implements **startAbilityByCall** to obtain the caller object for communication. The following example uses **this.context** to obtain the **context** attribute of the UIAbility, uses **startAbilityByCall** to start the CalleeAbility, obtain the caller object, and register the **onRelease** listener of the CallerAbility. You need to implement processing based on service requirements.
600
601
602   ```ts
603   // Register the onRelease() listener of the CallerAbility.
604   private regOnRelease(caller) {
605       try {
606           caller.on("release", (msg) => {
607               console.info(`caller onRelease is called ${msg}`);
608           })
609           console.info('caller register OnRelease succeed');
610       } catch (error) {
611           console.info(`caller register OnRelease failed with ${error}`);
612       }
613   }
614
615   async onButtonGetCaller() {
616       try {
617           this.caller = await context.startAbilityByCall({
618               bundleName: 'com.samples.CallApplication',
619               abilityName: 'CalleeAbility'
620           })
621           if (this.caller === undefined) {
622               console.info('get caller failed')
623               return
624           }
625           console.info('get caller success')
626           this.regOnRelease(this.caller)
627       } catch (error) {
628           console.info(`get caller failed with ${error}`)
629       }
630   }
631   ```
632