• 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 Ability Call to Implement UIAbility Interaction (for System Applications Only)](#using-ability-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 ability-level context 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 caller 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 ability-level context 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 ability-level context 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 ability-level context of the callee UIAbility.
115   this.context.terminateSelfWithResult(abilityResult, (err) => {
116       // ...
117   });
118   ```
119
1203. After FuncAbility stops itself, EntryAbility uses the **startAbilityForResult()** method 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 ability-level context of the initiator UIAbility.
128   this.context.startAbilityForResult(want).then((data) => {
129       if (data?.resultCode === RESULT_CODE) {
130           // Parse the information returned by the callee 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 caller.
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 the **startAbility()** method 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 additional type 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 caller'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 ability-level context 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 ability-level context 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 the **startAbilityForResult()** method. 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 the **startAbilityForResult()** method to start the UIAbility of the payment application. Include **entities** and **actions** of the caller'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 caller 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 ability-level context 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 the **terminateSelfWithResult()** method 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 ability-level context of the callee UIAbility.
278   this.context.terminateSelfWithResult(abilityResult, (err) => {
279       // ...
280   });
281   ```
282
2834. Receive the information returned by the payment application in the callback of the **startAbilityForResult()** method. 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 ability-level context of the initiator UIAbility.
293   this.context.startAbilityForResult(want).then((data) => {
294       if (data?.resultCode === RESULT_CODE) {
295           // Parse the information returned by the callee 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 caller 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 ability-level context 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 caller UIAbility.
348        this.funcAbilityWant = want;
349    }
350
351    onWindowStageCreate(windowStage: Window.WindowStage) {
352        // Main window is created. Set a main page for this ability.
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 caller 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> When the [launch type of the callee UIAbility](uiability-launch-type.md) is set to **standard**, a new instance is created each time the callee UIAbility is started. In this case, the [onNewWant()](../reference/apis/js-apis-app-ability-uiAbility.md#abilityonnewwant) callback will not be invoked.
416
417
418## Using Ability Call to Implement UIAbility Interaction (for System Applications Only)
419
420Ability call 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 ability call to implement data sharing between two UIAbility instances (caller ability and callee ability) through IPC.
421
422The core API used for the ability call is **startAbilityByCall**, which differs from **startAbility** in the following ways:
423
424- **startAbilityByCall** supports ability launch in the foreground and background, whereas **startAbility** supports ability launch in the foreground only.
425
426- The caller ability can use the caller object returned by **startAbilityByCall** to communicate with the callee ability, but **startAbility** does not provide the communication capability.
427
428Ability call is usually used in the following scenarios:
429
430- Communicating with the callee ability
431
432- Starting the callee ability in the background
433
434**Table 1** Terms used in the ability call
435
436| **Term**| Description|
437| -------- | -------- |
438| CallerAbility | UIAbility that triggers the ability call.|
439| CalleeAbility | UIAbility invoked by the ability call.|
440| Caller | Object returned by **startAbilityByCall** and used by the caller ability to communicate with the callee ability.|
441| Callee | Object held by the callee ability to communicate with the caller ability.|
442
443The following figure shows the ability call process.
444
445  Figure 1 Ability call process
446
447  ![call](figures/call.png)
448
449- The caller ability uses **startAbilityByCall** to obtain a caller object and uses **call()** of the caller object to send data to the callee ability.
450
451- The callee ability, which holds a **Callee** object, uses **on()** of the **Callee** object to register a callback. This callback is invoked when the callee ability receives data from the caller ability.
452
453> **NOTE**
454> 1. Currently, only system applications can use the ability call.
455>
456> 2. The launch type of the callee ability must be **singleton**.
457>
458> 3. Both local (intra-device) and cross-device ability calls are supported. The following describes how to initiate a local call. For details about how to initiate a cross-device ability call, see [Using Cross-Device Ability Call](hop-multi-device-collaboration.md#using-cross-device-ability-call).
459
460
461### Available APIs
462
463The following table describes the main APIs used for the ability call. For details, see [AbilityContext](../reference/apis/js-apis-app-ability-uiAbility.md#caller).
464
465  **Table 2** Ability call APIs
466
467| API| Description|
468| -------- | -------- |
469| 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).|
470| on(method: string, callback: CalleeCallBack): void | Callback invoked when the callee ability registers a method.|
471| off(method: string): void | Callback invoked when the callee ability deregisters a method.|
472| call(method: string, data: rpc.Parcelable): Promise<void> | Sends agreed parcelable data to the callee ability.|
473| callWithResult(method: string, data: rpc.Parcelable): Promise<rpc.MessageSequence> | Sends agreed parcelable data to the callee ability and obtains the agreed parcelable data returned by the callee ability.|
474| release(): void | Releases the caller object.|
475| on(type: "release", callback: OnReleaseCallback): void | Callback invoked when the caller object is released.|
476
477The implementation of using the ability call for UIAbility interaction involves two parts.
478
479- [Creating a Callee Ability](#creating-a-callee-ability)
480
481- [Accessing the Callee Ability](#accessing-the-callee-ability)
482
483
484### Creating a Callee Ability
485
486For the callee ability, 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.
487
4881. Configure the ability launch type.
489   Set **launchType** of the callee ability to **singleton** in the **module.json5** file.
490
491   | JSON Field| Description|
492   | -------- | -------- |
493   | "launchType" | Ability launch type. Set this parameter to **singleton**.|
494
495   An example of the ability configuration is as follows:
496
497
498   ```json
499   "abilities":[{
500     "name": ".CalleeAbility",
501     "srcEntrance": "./ets/CalleeAbility/CalleeAbility.ts",
502     "launchType": "singleton",
503     "description": "$string:CalleeAbility_desc",
504     "icon": "$media:icon",
505     "label": "$string:CalleeAbility_label",
506     "visible": true
507   }]
508   ```
509
5102. Import the **UIAbility** module.
511
512   ```ts
513   import Ability from '@ohos.app.ability.UIAbility';
514   ```
515
5163. Define the agreed parcelable data.
517   The data formats sent and received by the caller and callee abilities must be consistent. In the following example, the data formats are number and string.
518
519
520   ```ts
521   export default class MyParcelable {
522       num: number = 0
523       str: string = ""
524
525       constructor(num, string) {
526           this.num = num
527           this.str = string
528       }
529
530       marshalling(messageSequence) {
531           messageSequence.writeInt(this.num)
532           messageSequence.writeString(this.str)
533           return true
534       }
535
536       unmarshalling(messageSequence) {
537           this.num = messageSequence.readInt()
538           this.str = messageSequence.readString()
539           return true
540       }
541   }
542   ```
543
5444. Implement **Callee.on** and **Callee.off**.
545   The time to register a listener for the callee ability 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 ability 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:
546
547
548   ```ts
549   const TAG: string = '[CalleeAbility]';
550   const MSG_SEND_METHOD: string = 'CallSendMsg';
551
552   function sendMsgCallback(data) {
553       console.info('CalleeSortFunc called');
554
555       // Obtain the parcelable data sent by the caller ability.
556       let receivedData = new MyParcelable(0, '');
557       data.readParcelable(receivedData);
558       console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`);
559
560       // Process the data.
561       // Return the parcelable data result to the caller ability.
562       return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`);
563   }
564
565   export default class CalleeAbility extends Ability {
566       onCreate(want, launchParam) {
567           try {
568               this.callee.on(MSG_SEND_METHOD, sendMsgCallback);
569           } catch (error) {
570               console.info(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`);
571           }
572       }
573
574       onDestroy() {
575           try {
576               this.callee.off(MSG_SEND_METHOD);
577           } catch (error) {
578               console.error(TAG, `${MSG_SEND_METHOD} unregister failed with error ${JSON.stringify(error)}`);
579           }
580       }
581   }
582   ```
583
584
585### Accessing the Callee Ability
586
5871. Import the **UIAbility** module.
588
589   ```ts
590   import Ability from '@ohos.app.ability.UIAbility';
591   ```
592
5932. Obtain the caller interface.
594   The **context** attribute of the ability implements **startAbilityByCall** to obtain the caller object for communication. The following example uses **this.context** to obtain the **context** attribute of the ability, uses **startAbilityByCall** to start the callee ability, obtain the caller object, and register the **onRelease** listener of the caller ability. You need to implement processing based on service requirements.
595
596
597   ```ts
598   // Register the onRelease() listener of the caller ability.
599   private regOnRelease(caller) {
600       try {
601           caller.on("release", (msg) => {
602               console.info(`caller onRelease is called ${msg}`);
603           })
604           console.info('caller register OnRelease succeed');
605       } catch (error) {
606           console.info(`caller register OnRelease failed with ${error}`);
607       }
608   }
609
610   async onButtonGetCaller() {
611       try {
612           this.caller = await context.startAbilityByCall({
613               bundleName: 'com.samples.CallApplication',
614               abilityName: 'CalleeAbility'
615           })
616           if (this.caller === undefined) {
617               console.info('get caller failed')
618               return
619           }
620           console.info('get caller success')
621           this.regOnRelease(this.caller)
622       } catch (error) {
623           console.info(`get caller failed with ${error}`)
624       }
625   }
626   ```
627