1e41f4b71Sopenharmony_ci# Starting UIAbility in the Same Application
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci[UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) is the minimum unit that can be scheduled by the system. Redirection between functional modules in a device involves starting of specific UIAbility components, which belong to the same or a different application (for example, starting the UIAbility of a third-party payment application).
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThis topic describes how to start the UIAbility component that belongs to the same application. For details about component redirection between applications, see [Application Redirection](link-between-apps-overview.md). <!--Del-->For details about cross-device application component interaction, see [Inter-Device Application Component Interaction (Hopping)](inter-device-interaction-hop-overview.md).<!--DelEnd-->
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci- [Starting UIAbility in the Same Application](#starting-uiability-in-the-same-application)
11e41f4b71Sopenharmony_ci- [Starting UIAbility in the Same Application and Obtaining the Return Result](#starting-uiability-in-the-same-application-and-obtaining-the-return-result)
12e41f4b71Sopenharmony_ci- [Starting a Specified Page of UIAbility](#starting-a-specified-page-of-uiability)
13e41f4b71Sopenharmony_ci<!--Del-->
14e41f4b71Sopenharmony_ci- [Starting UIAbility with Window Mode Specified (for System Applications Only)](#starting-uiability-with-window-mode-specified-for-system-applications-only)
15e41f4b71Sopenharmony_ci- [Using Call to Implement UIAbility Interaction (for System Applications Only)](#using-call-to-implement-uiability-interaction-for-system-applications-only)
16e41f4b71Sopenharmony_ci<!--DelEnd-->
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## Starting UIAbility in the Same Application
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciThis scenario is possible when an application contains multiple [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) components. For example, in a payment application, you may need to start the payment UIAbility from the entry UIAbility.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciAssume 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:
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci1. In EntryAbility, call [startAbility()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) and pass the [want](../reference/apis-ability-kit/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).
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci    ```ts
28e41f4b71Sopenharmony_ci    import { common, Want } from '@kit.AbilityKit';
29e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
30e41f4b71Sopenharmony_ci    import { BusinessError } from '@kit.BasicServicesKit';
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci    const TAG: string = '[Page_UIAbilityComponentsInteractive]';
33e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci    @Entry
36e41f4b71Sopenharmony_ci    @Component
37e41f4b71Sopenharmony_ci    struct Page_UIAbilityComponentsInteractive {
38e41f4b71Sopenharmony_ci      private context = getContext(this) as common.UIAbilityContext;
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci      build() {
41e41f4b71Sopenharmony_ci        Column() {
42e41f4b71Sopenharmony_ci          //...
43e41f4b71Sopenharmony_ci          List({ initialIndex: 0 }) {
44e41f4b71Sopenharmony_ci            ListItem() {
45e41f4b71Sopenharmony_ci              Row() {
46e41f4b71Sopenharmony_ci                //...
47e41f4b71Sopenharmony_ci              }
48e41f4b71Sopenharmony_ci              .onClick(() => {
49e41f4b71Sopenharmony_ci                // Context is a member of the ability object and is required for invoking inside a non-ability object.
50e41f4b71Sopenharmony_ci                // Pass in the Context object.
51e41f4b71Sopenharmony_ci                let wantInfo: Want = {
52e41f4b71Sopenharmony_ci                  deviceId: '', // An empty deviceId indicates the local device.
53e41f4b71Sopenharmony_ci                  bundleName: 'com.samples.stagemodelabilitydevelop',
54e41f4b71Sopenharmony_ci                  moduleName: 'entry', // moduleName is optional.
55e41f4b71Sopenharmony_ci                  abilityName: 'FuncAbilityA',
56e41f4b71Sopenharmony_ci                  parameters: {
57e41f4b71Sopenharmony_ci                    // Custom information.
58e41f4b71Sopenharmony_ci                    info: 'From Page_UIAbilityComponentsInteractive of EntryAbility',
59e41f4b71Sopenharmony_ci                  },
60e41f4b71Sopenharmony_ci                };
61e41f4b71Sopenharmony_ci                // context is the UIAbilityContext of the initiator UIAbility.
62e41f4b71Sopenharmony_ci                this.context.startAbility(wantInfo).then(() => {
63e41f4b71Sopenharmony_ci                  hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.');
64e41f4b71Sopenharmony_ci                }).catch((error: BusinessError) => {
65e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN_NUMBER, TAG, 'startAbility failed.');
66e41f4b71Sopenharmony_ci                });
67e41f4b71Sopenharmony_ci              })
68e41f4b71Sopenharmony_ci            }
69e41f4b71Sopenharmony_ci            //...
70e41f4b71Sopenharmony_ci          }
71e41f4b71Sopenharmony_ci          //...
72e41f4b71Sopenharmony_ci        }
73e41f4b71Sopenharmony_ci        //...
74e41f4b71Sopenharmony_ci      }
75e41f4b71Sopenharmony_ci    }
76e41f4b71Sopenharmony_ci    ```
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci2. In FuncAbility, use [onCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityoncreate) or [onNewWant()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonnewwant) to receive the parameters passed in by EntryAbility.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci    ```ts
81e41f4b71Sopenharmony_ci    import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci    export default class FuncAbilityA extends UIAbility {
84e41f4b71Sopenharmony_ci      onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
85e41f4b71Sopenharmony_ci        // Receive the parameters passed by the initiator UIAbility.
86e41f4b71Sopenharmony_ci        let funcAbilityWant = want;
87e41f4b71Sopenharmony_ci        let info = funcAbilityWant?.parameters?.info;
88e41f4b71Sopenharmony_ci      }
89e41f4b71Sopenharmony_ci      //...
90e41f4b71Sopenharmony_ci    }
91e41f4b71Sopenharmony_ci    ```
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci    > **NOTE**
94e41f4b71Sopenharmony_ci    >
95e41f4b71Sopenharmony_ci    > In FuncAbility started, you can obtain the PID and bundle name of the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) through **parameters** in the passed [want](../reference/apis-ability-kit/js-apis-app-ability-want.md) parameter.
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci3. To stop the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) instance after the FuncAbility service is not needed, call [terminateSelf()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateself) in FuncAbility.
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci    ```ts
100e41f4b71Sopenharmony_ci    import { common } from '@kit.AbilityKit';
101e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci    const TAG: string = '[Page_FromStageModel]';
104e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci    @Entry
107e41f4b71Sopenharmony_ci    @Component
108e41f4b71Sopenharmony_ci    struct Page_FromStageModel {
109e41f4b71Sopenharmony_ci      build() {
110e41f4b71Sopenharmony_ci        Column() {
111e41f4b71Sopenharmony_ci          //...
112e41f4b71Sopenharmony_ci          Button('FuncAbilityB')
113e41f4b71Sopenharmony_ci            .onClick(() => {
114e41f4b71Sopenharmony_ci              let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
115e41f4b71Sopenharmony_ci              // context is the UIAbilityContext of the UIAbility instance to stop.
116e41f4b71Sopenharmony_ci              context.terminateSelf((err) => {
117e41f4b71Sopenharmony_ci                if (err.code) {
118e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`);
119e41f4b71Sopenharmony_ci                  return;
120e41f4b71Sopenharmony_ci                }
121e41f4b71Sopenharmony_ci              });
122e41f4b71Sopenharmony_ci            })
123e41f4b71Sopenharmony_ci        }
124e41f4b71Sopenharmony_ci        //...
125e41f4b71Sopenharmony_ci      }
126e41f4b71Sopenharmony_ci    }
127e41f4b71Sopenharmony_ci    ```
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci    > **NOTE**
130e41f4b71Sopenharmony_ci    >
131e41f4b71Sopenharmony_ci    > When **terminateSelf()** 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.
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci4. To stop all [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) instances of the application, call [killAllProcesses()](../reference/apis-ability-kit/js-apis-inner-application-applicationContext.md#applicationcontextkillallprocesses) of [ApplicationContext](../reference/apis-ability-kit/js-apis-inner-application-applicationContext.md).
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci## Starting UIAbility in the Same Application and Obtaining the Return Result
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ciWhen 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](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) of your application, you want the sign-in result to be returned to the entry UIAbility.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci1. In EntryAbility, call [startAbilityForResult()](../reference/apis-ability-kit/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).
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci    ```ts
143e41f4b71Sopenharmony_ci    import { common, Want } from '@kit.AbilityKit';
144e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
145e41f4b71Sopenharmony_ci    import { promptAction } from '@kit.ArkUI';
146e41f4b71Sopenharmony_ci    import { BusinessError } from '@kit.BasicServicesKit';
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci    const TAG: string = '[Page_UIAbilityComponentsInteractive]';
149e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci    @Entry
152e41f4b71Sopenharmony_ci    @Component
153e41f4b71Sopenharmony_ci    struct Page_UIAbilityComponentsInteractive {
154e41f4b71Sopenharmony_ci      build() {
155e41f4b71Sopenharmony_ci        Column() {
156e41f4b71Sopenharmony_ci          //...
157e41f4b71Sopenharmony_ci          List({ initialIndex: 0 }) {
158e41f4b71Sopenharmony_ci            ListItem() {
159e41f4b71Sopenharmony_ci              Row() {
160e41f4b71Sopenharmony_ci                //...
161e41f4b71Sopenharmony_ci              }
162e41f4b71Sopenharmony_ci              .onClick(() => {
163e41f4b71Sopenharmony_ci                let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
164e41f4b71Sopenharmony_ci                const RESULT_CODE: number = 1001;
165e41f4b71Sopenharmony_ci                let want: Want = {
166e41f4b71Sopenharmony_ci                  deviceId: '', // An empty deviceId indicates the local device.
167e41f4b71Sopenharmony_ci                  bundleName: 'com.samples.stagemodelabilitydevelop',
168e41f4b71Sopenharmony_ci                  moduleName: 'entry', // moduleName is optional.
169e41f4b71Sopenharmony_ci                  abilityName: 'FuncAbilityA',
170e41f4b71Sopenharmony_ci                  parameters: {
171e41f4b71Sopenharmony_ci                    // Custom information.
172e41f4b71Sopenharmony_ci                    info: 'From UIAbilityComponentsInteractive of EntryAbility',
173e41f4b71Sopenharmony_ci                  }
174e41f4b71Sopenharmony_ci                };
175e41f4b71Sopenharmony_ci                context.startAbilityForResult(want).then((data) => {
176e41f4b71Sopenharmony_ci                  if (data?.resultCode === RESULT_CODE) {
177e41f4b71Sopenharmony_ci                    // Parse the information returned by the target UIAbility.
178e41f4b71Sopenharmony_ci                    let info = data.want?.parameters?.info;
179e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? '');
180e41f4b71Sopenharmony_ci                    if (info !== null) {
181e41f4b71Sopenharmony_ci                      promptAction.showToast({
182e41f4b71Sopenharmony_ci                        message: JSON.stringify(info)
183e41f4b71Sopenharmony_ci                      });
184e41f4b71Sopenharmony_ci                    }
185e41f4b71Sopenharmony_ci                  }
186e41f4b71Sopenharmony_ci                  hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(data.resultCode) ?? '');
187e41f4b71Sopenharmony_ci                }).catch((err: BusinessError) => {
188e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
189e41f4b71Sopenharmony_ci                });
190e41f4b71Sopenharmony_ci              })
191e41f4b71Sopenharmony_ci            }
192e41f4b71Sopenharmony_ci            //...
193e41f4b71Sopenharmony_ci          }
194e41f4b71Sopenharmony_ci          //...
195e41f4b71Sopenharmony_ci        }
196e41f4b71Sopenharmony_ci        //...
197e41f4b71Sopenharmony_ci      }
198e41f4b71Sopenharmony_ci    }
199e41f4b71Sopenharmony_ci    ```
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci2. Call [terminateSelfWithResult()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextterminateselfwithresult) to stop FuncAbility. Use the input parameter [abilityResult](../reference/apis-ability-kit/js-apis-inner-ability-abilityResult.md) to carry the information that FuncAbility needs to return to EntryAbility.
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci    ```ts
204e41f4b71Sopenharmony_ci    import { common } from '@kit.AbilityKit';
205e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci    const TAG: string = '[Page_FuncAbilityA]';
208e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci    @Entry
211e41f4b71Sopenharmony_ci    @Component
212e41f4b71Sopenharmony_ci    struct Page_FuncAbilityA {
213e41f4b71Sopenharmony_ci      build() {
214e41f4b71Sopenharmony_ci        Column() {
215e41f4b71Sopenharmony_ci          //...
216e41f4b71Sopenharmony_ci          List({ initialIndex: 0 }) {
217e41f4b71Sopenharmony_ci            ListItem() {
218e41f4b71Sopenharmony_ci              Row() {
219e41f4b71Sopenharmony_ci                //...
220e41f4b71Sopenharmony_ci              }
221e41f4b71Sopenharmony_ci              .onClick(() => {
222e41f4b71Sopenharmony_ci                let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
223e41f4b71Sopenharmony_ci                const RESULT_CODE: number = 1001;
224e41f4b71Sopenharmony_ci                let abilityResult: common.AbilityResult = {
225e41f4b71Sopenharmony_ci                  resultCode: RESULT_CODE,
226e41f4b71Sopenharmony_ci                  want: {
227e41f4b71Sopenharmony_ci                    bundleName: 'com.samples.stagemodelabilitydevelop',
228e41f4b71Sopenharmony_ci                    moduleName: 'entry', // moduleName is optional.
229e41f4b71Sopenharmony_ci                    abilityName: 'FuncAbilityB',
230e41f4b71Sopenharmony_ci                    parameters: {
231e41f4b71Sopenharmony_ci                      info: 'From the Index page of FuncAbility',
232e41f4b71Sopenharmony_ci                    },
233e41f4b71Sopenharmony_ci                  },
234e41f4b71Sopenharmony_ci                };
235e41f4b71Sopenharmony_ci                context.terminateSelfWithResult(abilityResult, (err) => {
236e41f4b71Sopenharmony_ci                  if (err.code) {
237e41f4b71Sopenharmony_ci                    hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self with result. Code is ${err.code}, message is ${err.message}`);
238e41f4b71Sopenharmony_ci                    return;
239e41f4b71Sopenharmony_ci                  }
240e41f4b71Sopenharmony_ci                });
241e41f4b71Sopenharmony_ci              })
242e41f4b71Sopenharmony_ci            }
243e41f4b71Sopenharmony_ci            //...
244e41f4b71Sopenharmony_ci          }
245e41f4b71Sopenharmony_ci          //...
246e41f4b71Sopenharmony_ci        }
247e41f4b71Sopenharmony_ci        //...
248e41f4b71Sopenharmony_ci      }
249e41f4b71Sopenharmony_ci    }
250e41f4b71Sopenharmony_ci    ```
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci3. After FuncAbility stops itself, EntryAbility uses [startAbilityForResult()](../reference/apis-ability-kit/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.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci    ```ts
255e41f4b71Sopenharmony_ci    import { common, Want } from '@kit.AbilityKit';
256e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
257e41f4b71Sopenharmony_ci    import { promptAction } from '@kit.ArkUI';
258e41f4b71Sopenharmony_ci    import { BusinessError } from '@kit.BasicServicesKit';
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci    const TAG: string = '[Page_UIAbilityComponentsInteractive]';
261e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci    @Entry
264e41f4b71Sopenharmony_ci    @Component
265e41f4b71Sopenharmony_ci    struct Page_UIAbilityComponentsInteractive {
266e41f4b71Sopenharmony_ci      build() {
267e41f4b71Sopenharmony_ci        Column() {
268e41f4b71Sopenharmony_ci          //...
269e41f4b71Sopenharmony_ci          List({ initialIndex: 0 }) {
270e41f4b71Sopenharmony_ci            ListItem() {
271e41f4b71Sopenharmony_ci              Row() {
272e41f4b71Sopenharmony_ci                //...
273e41f4b71Sopenharmony_ci              }
274e41f4b71Sopenharmony_ci              .onClick(() => {
275e41f4b71Sopenharmony_ci                let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
276e41f4b71Sopenharmony_ci                const RESULT_CODE: number = 1001;
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci                let want: Want = {
279e41f4b71Sopenharmony_ci                  deviceId: '', // An empty deviceId indicates the local device.
280e41f4b71Sopenharmony_ci                  bundleName: 'com.samples.stagemodelabilitydevelop',
281e41f4b71Sopenharmony_ci                  moduleName: 'entry', // moduleName is optional.
282e41f4b71Sopenharmony_ci                  abilityName: 'FuncAbilityA',
283e41f4b71Sopenharmony_ci                  parameters: {
284e41f4b71Sopenharmony_ci                    // Custom information.
285e41f4b71Sopenharmony_ci                    info: 'From UIAbilityComponentsInteractive of EntryAbility',
286e41f4b71Sopenharmony_ci                  }
287e41f4b71Sopenharmony_ci                };
288e41f4b71Sopenharmony_ci                context.startAbilityForResult(want).then((data) => {
289e41f4b71Sopenharmony_ci                  if (data?.resultCode === RESULT_CODE) {
290e41f4b71Sopenharmony_ci                    // Parse the information returned by the target UIAbility.
291e41f4b71Sopenharmony_ci                    let info = data.want?.parameters?.info;
292e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? '');
293e41f4b71Sopenharmony_ci                    if (info !== null) {
294e41f4b71Sopenharmony_ci                      promptAction.showToast({
295e41f4b71Sopenharmony_ci                        message: JSON.stringify(info)
296e41f4b71Sopenharmony_ci                      });
297e41f4b71Sopenharmony_ci                    }
298e41f4b71Sopenharmony_ci                  }
299e41f4b71Sopenharmony_ci                  hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(data.resultCode) ?? '');
300e41f4b71Sopenharmony_ci                }).catch((err: BusinessError) => {
301e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability for result. Code is ${err.code}, message is ${err.message}`);
302e41f4b71Sopenharmony_ci                });
303e41f4b71Sopenharmony_ci              })
304e41f4b71Sopenharmony_ci            }
305e41f4b71Sopenharmony_ci            //...
306e41f4b71Sopenharmony_ci          }
307e41f4b71Sopenharmony_ci          //...
308e41f4b71Sopenharmony_ci        }
309e41f4b71Sopenharmony_ci        //...
310e41f4b71Sopenharmony_ci      }
311e41f4b71Sopenharmony_ci    }
312e41f4b71Sopenharmony_ci    ```
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci## Starting a Specified Page of UIAbility
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci### Overview
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ciA [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) component can have multiple pages that each display in specific scenarios.
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ciA UIAbility component can be started in two modes:
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci- Cold start: The UIAbility instance is totally closed before being started. This requires that the code and resources of the UIAbility instance be completely loaded and initialized.
324e41f4b71Sopenharmony_ci- Hot start: The UIAbility instance has been started, running in the foreground, and then switched to the background before being started again. In this case, the status of the UIAbility instance can be quickly restored.
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ciThis section describes how to start a specified page in both modes: [cold start](#cold-starting-uiability) and [hot start](#hot-starting-uiability). Before starting a specified page, you will learn how to specify a startup page on the initiator UIAbility.
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci### Specifying a Startup Page
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ciWhen the initiator [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) starts another UIAbility, it usually needs to redirect to a specified page of the target UIAbility. For example, with FuncAbility, which contains two pages, starting FuncAbility means to redirect to either of the pages: Index (corresponding to the home page) and Second (corresponding to feature A page). You can configure the specified page URL in the want parameter by adding a custom parameter to parameters in [want](../reference/apis-ability-kit/js-apis-app-ability-want.md). 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).
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci```ts
335e41f4b71Sopenharmony_ciimport { common, Want } from '@kit.AbilityKit';
336e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
337e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ciconst TAG: string = '[Page_UIAbilityComponentsInteractive]';
340e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00;
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci@Entry
343e41f4b71Sopenharmony_ci@Component
344e41f4b71Sopenharmony_cistruct Page_UIAbilityComponentsInteractive {
345e41f4b71Sopenharmony_ci  build() {
346e41f4b71Sopenharmony_ci    Column() {
347e41f4b71Sopenharmony_ci      //...
348e41f4b71Sopenharmony_ci      List({ initialIndex: 0 }) {
349e41f4b71Sopenharmony_ci        ListItem() {
350e41f4b71Sopenharmony_ci          Row() {
351e41f4b71Sopenharmony_ci            //...
352e41f4b71Sopenharmony_ci          }
353e41f4b71Sopenharmony_ci          .onClick(() => {
354e41f4b71Sopenharmony_ci            let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
355e41f4b71Sopenharmony_ci            let want: Want = {
356e41f4b71Sopenharmony_ci              deviceId: '', // An empty deviceId indicates the local device.
357e41f4b71Sopenharmony_ci              bundleName: 'com.samples.stagemodelabilityinteraction',
358e41f4b71Sopenharmony_ci              moduleName: 'entry', // moduleName is optional.
359e41f4b71Sopenharmony_ci              abilityName: 'FuncAbility',
360e41f4b71Sopenharmony_ci              parameters: { // Custom parameter used to pass the page information.
361e41f4b71Sopenharmony_ci                router: 'funcA'
362e41f4b71Sopenharmony_ci              }
363e41f4b71Sopenharmony_ci            };
364e41f4b71Sopenharmony_ci            // context is the UIAbilityContext of the initiator UIAbility.
365e41f4b71Sopenharmony_ci            context.startAbility(want).then(() => {
366e41f4b71Sopenharmony_ci              hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.');
367e41f4b71Sopenharmony_ci            }).catch((err: BusinessError) => {
368e41f4b71Sopenharmony_ci              hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`);
369e41f4b71Sopenharmony_ci            });
370e41f4b71Sopenharmony_ci          })
371e41f4b71Sopenharmony_ci        }
372e41f4b71Sopenharmony_ci        //...
373e41f4b71Sopenharmony_ci      }
374e41f4b71Sopenharmony_ci      //...
375e41f4b71Sopenharmony_ci    }
376e41f4b71Sopenharmony_ci    //...
377e41f4b71Sopenharmony_ci  }
378e41f4b71Sopenharmony_ci}
379e41f4b71Sopenharmony_ci```
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci### Cold Starting UIAbility
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ciIn cold start mode, obtain the parameters from the initiator [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) through the [onCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityoncreate) callback of the target UIAbility. Then, in the [onWindowStageCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) callback of the target UIAbility, parse the [want](../reference/apis-ability-kit/js-apis-app-ability-want.md) parameter passed by the EntryAbility to obtain the URL of the page to be loaded, and pass the URL to the [windowStage.loadContent()](../reference/apis-arkui/js-apis-window.md#loadcontent9) method.
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci
387e41f4b71Sopenharmony_ci```ts
388e41f4b71Sopenharmony_ciimport { AbilityConstant, Want, UIAbility } from '@kit.AbilityKit';
389e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
390e41f4b71Sopenharmony_ciimport { window, UIContext } from '@kit.ArkUI';
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00;
393e41f4b71Sopenharmony_ciconst TAG: string = '[EntryAbility]';
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
396e41f4b71Sopenharmony_ci  funcAbilityWant: Want | undefined = undefined;
397e41f4b71Sopenharmony_ci  uiContext: UIContext | undefined = undefined;
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_ci  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
400e41f4b71Sopenharmony_ci    // Receive the parameters passed by the initiator UIAbility.
401e41f4b71Sopenharmony_ci    this.funcAbilityWant = want;
402e41f4b71Sopenharmony_ci  }
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci  onWindowStageCreate(windowStage: window.WindowStage): void {
405e41f4b71Sopenharmony_ci    // Main window is created. Set a main page for this UIAbility.
406e41f4b71Sopenharmony_ci    hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate');
407e41f4b71Sopenharmony_ci    // Main window is created. Set a main page for this UIAbility.
408e41f4b71Sopenharmony_ci    let url = 'pages/Index';
409e41f4b71Sopenharmony_ci    if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'funcA') {
410e41f4b71Sopenharmony_ci      url = 'pages/Page_ColdStartUp';
411e41f4b71Sopenharmony_ci    }
412e41f4b71Sopenharmony_ci    windowStage.loadContent(url, (err, data) => {
413e41f4b71Sopenharmony_ci      // ...
414e41f4b71Sopenharmony_ci    });
415e41f4b71Sopenharmony_ci  }
416e41f4b71Sopenharmony_ci}
417e41f4b71Sopenharmony_ci```
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci### Hot Starting UIAbility
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ciIf the target [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) has been started, the initialization logic is not executed again. Instead, the [onNewWant()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonnewwant) lifecycle callback is directly triggered. To implement redirection, parse the required parameters in **onNewWant()**.
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ciAn example scenario is as follows:
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci1. A user opens the SMS application. The UIAbility instance of the SMS application is started, and the home page of the application is displayed.
426e41f4b71Sopenharmony_ci2. The user returns to the home screen, and the SMS application switches to the background.
427e41f4b71Sopenharmony_ci3. The user opens the Contacts application and finds a contact.
428e41f4b71Sopenharmony_ci4. The user touches the SMS button next to the contact. The UIAbility instance of the SMS application is restarted.
429e41f4b71Sopenharmony_ci5. Since the UIAbility instance of the SMS application has been started, the onNewWant() callback of the UIAbility is triggered, and the initialization logic such as [onCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityoncreate) and [onWindowStageCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) is skipped.
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**Figure 1** Hot starting the target UIAbility
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci![](figures/uiability-hot-start.png)
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ciThe development procedure is as follows:
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci1. When the UIAbility instance of the SMS application is cold started, call [getUIContext()](../reference/apis-arkui/js-apis-window.md#getuicontext10) in the [onWindowStageCreate()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonwindowstagecreate) lifecycle callback to obtain the [UIContext](../reference/apis-arkui/js-apis-arkui-UIContext.md).
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci    ```ts
440e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
441e41f4b71Sopenharmony_ci    import { Want, UIAbility } from '@kit.AbilityKit';
442e41f4b71Sopenharmony_ci    import { window, UIContext } from '@kit.ArkUI';
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
445e41f4b71Sopenharmony_ci    const TAG: string = '[EntryAbility]';
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci    export default class EntryAbility extends UIAbility {
448e41f4b71Sopenharmony_ci      funcAbilityWant: Want | undefined = undefined;
449e41f4b71Sopenharmony_ci      uiContext: UIContext | undefined = undefined;
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci      // ...
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci      onWindowStageCreate(windowStage: window.WindowStage): void {
454e41f4b71Sopenharmony_ci        // Main window is created. Set a main page for this UIAbility.
455e41f4b71Sopenharmony_ci        hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate');
456e41f4b71Sopenharmony_ci        let url = 'pages/Index';
457e41f4b71Sopenharmony_ci        if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'funcA') {
458e41f4b71Sopenharmony_ci          url = 'pages/Page_ColdStartUp';
459e41f4b71Sopenharmony_ci        }
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ci        windowStage.loadContent(url, (err, data) => {
462e41f4b71Sopenharmony_ci          if (err.code) {
463e41f4b71Sopenharmony_ci            return;
464e41f4b71Sopenharmony_ci          }
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci          let windowClass: window.Window;
467e41f4b71Sopenharmony_ci          windowStage.getMainWindow((err, data) => {
468e41f4b71Sopenharmony_ci            if (err.code) {
469e41f4b71Sopenharmony_ci              hilog.error(DOMAIN_NUMBER, TAG, `Failed to obtain the main window. Code is ${err.code}, message is ${err.message}`);
470e41f4b71Sopenharmony_ci              return;
471e41f4b71Sopenharmony_ci            }
472e41f4b71Sopenharmony_ci            windowClass = data;
473e41f4b71Sopenharmony_ci            this.uiContext = windowClass.getUIContext();
474e41f4b71Sopenharmony_ci          });
475e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
476e41f4b71Sopenharmony_ci        });
477e41f4b71Sopenharmony_ci      }
478e41f4b71Sopenharmony_ci    }
479e41f4b71Sopenharmony_ci    ```
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_ci2. Parse the [want](../reference/apis-ability-kit/js-apis-app-ability-want.md) parameter passed in the [onNewWant()](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityonnewwant) callback of the UIAbility of the SMS application, call [[getRouter()](../reference/apis-arkui/js-apis-arkui-UIContext.md#getrouter) in the [UIContext](../reference/apis-arkui/js-apis-arkui-UIContext.md) class to obtain a [Router](../reference/apis-arkui/js-apis-arkui-UIContext.md#router) instance, and specify the target page. When the UIAbility instance of the SMS application is started again, the specified page of the UIAbility instance of the SMS application is displayed.
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci    ```ts
484e41f4b71Sopenharmony_ci    import { AbilityConstant, Want, UIAbility } from '@kit.AbilityKit';
485e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
486e41f4b71Sopenharmony_ci    import type { Router, UIContext } from '@kit.ArkUI';
487e41f4b71Sopenharmony_ci    import type { BusinessError } from '@kit.BasicServicesKit';
488e41f4b71Sopenharmony_ci   
489e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
490e41f4b71Sopenharmony_ci    const TAG: string = '[EntryAbility]';
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci    export default class EntryAbility extends UIAbility {
493e41f4b71Sopenharmony_ci      funcAbilityWant: Want | undefined = undefined;
494e41f4b71Sopenharmony_ci      uiContext: UIContext | undefined = undefined;
495e41f4b71Sopenharmony_ci      // ...
496e41f4b71Sopenharmony_ci      onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
497e41f4b71Sopenharmony_ci        if (want?.parameters?.router && want.parameters.router === 'funcA') {
498e41f4b71Sopenharmony_ci          let funcAUrl = 'pages/Page_HotStartUp';
499e41f4b71Sopenharmony_ci          if (this.uiContext) {
500e41f4b71Sopenharmony_ci            let router: Router = this.uiContext.getRouter();
501e41f4b71Sopenharmony_ci            router.pushUrl({
502e41f4b71Sopenharmony_ci              url: funcAUrl
503e41f4b71Sopenharmony_ci            }).catch((err: BusinessError) => {
504e41f4b71Sopenharmony_ci              hilog.error(DOMAIN_NUMBER, TAG, `Failed to push url. Code is ${err.code}, message is ${err.message}`);
505e41f4b71Sopenharmony_ci            });
506e41f4b71Sopenharmony_ci          }
507e41f4b71Sopenharmony_ci        }
508e41f4b71Sopenharmony_ci      }
509e41f4b71Sopenharmony_ci    }
510e41f4b71Sopenharmony_ci    ```
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci> **NOTE**
513e41f4b71Sopenharmony_ci>
514e41f4b71Sopenharmony_ci> When the [launch type of the target UIAbility](uiability-launch-type.md) is set to **multiton**, a new instance is created each time the target UIAbility is started. In this case, the **onNewWant()** callback will not be invoked.
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci<!--Del-->
517e41f4b71Sopenharmony_ci## Starting UIAbility with Window Mode Specified (for System Applications Only)
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ciBy specifying the window mode when starting the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) of an application, you can have the application displayed in the specified window mode, which can be full-screen, floating window, or split-screen.
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ciIn full-screen mode, an application occupies the entire screen after being started. Users cannot view other windows or applications. This mode is suitable for an application that requires users to focus on a specific task or UI.
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_ciIn floating window mode, an application is displayed on the screen as a floating window after being started. Users can easily switch to other windows or applications. This mode is suitable for an application that allows users to process multiple tasks at the same time.
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ciIn split-screen mode, two applications occupy the entire screen, side by side, horizontally or vertically. This mode helps users improve multi-task processing efficiency.
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ciThe window mode is specified by the **windowMode** field in the [StartOptions](../reference/apis-ability-kit/js-apis-app-ability-startOptions.md) parameter of [startAbility()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability).
528e41f4b71Sopenharmony_ci
529e41f4b71Sopenharmony_ci> **NOTE**
530e41f4b71Sopenharmony_ci>
531e41f4b71Sopenharmony_ci> - If the **windowMode** field is not specified, the UIAbility is started in the default window mode.
532e41f4b71Sopenharmony_ci> - 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.
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ciThe following describes how to start the FuncAbility from the EntryAbility page and display it in floating window mode.
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci1. Add the **StartOptions** parameter in **startAbility()**.
537e41f4b71Sopenharmony_ci2. Set the **windowMode** field in the **StartOptions** parameter to **WINDOW_MODE_FLOATING**. This setting applies only to a system application.
538e41f4b71Sopenharmony_ci3. In the case of a third-party application, set the **displayId** field instead.
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ciFor details about how to obtain the context in the example, see [Obtaining the Context of UIAbility](uiability-usage.md#obtaining-the-context-of-uiability).
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci```ts
543e41f4b71Sopenharmony_ciimport { AbilityConstant, common, Want, StartOptions } from '@kit.AbilityKit';
544e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
545e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ciconst TAG: string = '[Page_UIAbilityComponentsInteractive]';
548e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00;
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci@Entry
551e41f4b71Sopenharmony_ci@Component
552e41f4b71Sopenharmony_cistruct Page_UIAbilityComponentsInteractive {
553e41f4b71Sopenharmony_ci  build() {
554e41f4b71Sopenharmony_ci    Column() {
555e41f4b71Sopenharmony_ci      //...
556e41f4b71Sopenharmony_ci      List({ initialIndex: 0 }) {
557e41f4b71Sopenharmony_ci        ListItem() {
558e41f4b71Sopenharmony_ci          Row() {
559e41f4b71Sopenharmony_ci            //...
560e41f4b71Sopenharmony_ci          }
561e41f4b71Sopenharmony_ci          .onClick(() => {
562e41f4b71Sopenharmony_ci            let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
563e41f4b71Sopenharmony_ci            let want: Want = {
564e41f4b71Sopenharmony_ci              deviceId: '', // An empty deviceId indicates the local device.
565e41f4b71Sopenharmony_ci              bundleName: 'com.samples.stagemodelabilitydevelop',
566e41f4b71Sopenharmony_ci              moduleName: 'entry', // moduleName is optional.
567e41f4b71Sopenharmony_ci              abilityName: 'FuncAbilityB',
568e41f4b71Sopenharmony_ci              parameters: {
569e41f4b71Sopenharmony_ci                // Custom information.
570e41f4b71Sopenharmony_ci                info: 'From the Index page of EntryAbility',
571e41f4b71Sopenharmony_ci              }
572e41f4b71Sopenharmony_ci            };
573e41f4b71Sopenharmony_ci            let options: StartOptions = {
574e41f4b71Sopenharmony_ci              windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING
575e41f4b71Sopenharmony_ci            };
576e41f4b71Sopenharmony_ci            // context is the UIAbilityContext of the initiator UIAbility.
577e41f4b71Sopenharmony_ci            context.startAbility(want, options).then(() => {
578e41f4b71Sopenharmony_ci              hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.');
579e41f4b71Sopenharmony_ci            }).catch((err: BusinessError) => {
580e41f4b71Sopenharmony_ci              hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`);
581e41f4b71Sopenharmony_ci            });
582e41f4b71Sopenharmony_ci          })
583e41f4b71Sopenharmony_ci        }
584e41f4b71Sopenharmony_ci        //...
585e41f4b71Sopenharmony_ci      }
586e41f4b71Sopenharmony_ci      //...
587e41f4b71Sopenharmony_ci    }
588e41f4b71Sopenharmony_ci    //...
589e41f4b71Sopenharmony_ci  }
590e41f4b71Sopenharmony_ci}
591e41f4b71Sopenharmony_ci```
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ciThe display effect is shown below.
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci![](figures/start-uiability-floating-window.png)
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci## Using Call to Implement UIAbility Interaction (for System Applications Only)
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ciCall is an extension of the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) 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.
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ciThe core API used for the call is [startAbilityByCall()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall), which differs from [startAbility()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) in the following ways:
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_ci- **startAbilityByCall()** supports UIAbility launch in the foreground and background, whereas **startAbility()** supports UIAbility launch in the foreground only.
605e41f4b71Sopenharmony_ci
606e41f4b71Sopenharmony_ci- The CallerAbility can use the [Caller](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#caller) object returned by **startAbilityByCall()** to communicate with the CalleeAbility, but **startAbility()** does not provide the communication capability.
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ciCall is usually used in the following scenarios:
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci- Communicating with the CalleeAbility
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci- Starting the CalleeAbility in the background
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci**Table 1** Terms used in the call
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci| **Term**| Description|
618e41f4b71Sopenharmony_ci| -------- | -------- |
619e41f4b71Sopenharmony_ci| CallerAbility| UIAbility that triggers the call.|
620e41f4b71Sopenharmony_ci| CalleeAbility | UIAbility invoked by the call.|
621e41f4b71Sopenharmony_ci| Caller | Object returned by **startAbilityByCall** and used by the CallerAbility to communicate with the CalleeAbility.|
622e41f4b71Sopenharmony_ci| Callee | Object held by the CalleeAbility to communicate with the CallerAbility.|
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ciThe following figure shows the call process.
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ci**Figure 1** Call process
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci![call](figures/call.png)
629e41f4b71Sopenharmony_ci
630e41f4b71Sopenharmony_ci- The CallerAbility uses [startAbilityByCall()](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall) to obtain a [Caller](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#caller) object and uses [call](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#callercall) of the Caller object to send data to the CalleeAbility.
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci- The CalleeAbility, which holds a [Callee](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#callee) object, uses [on](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleeon) of the Callee object to register a callback. This callback is invoked when the CalleeAbility receives data from the CallerAbility.
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ci> **NOTE**
635e41f4b71Sopenharmony_ci>
636e41f4b71Sopenharmony_ci> Currently, only system applications can use the call.
637e41f4b71Sopenharmony_ci>
638e41f4b71Sopenharmony_ci> The launch type of the CalleeAbility must be **singleton**.
639e41f4b71Sopenharmony_ci>
640e41f4b71Sopenharmony_ci> 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).
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci### Available APIs
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ciThe following table describes the main APIs used for the call. For details, see [AbilityContext](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#caller).
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci**Table 2** Call APIs
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci| API| Description|
650e41f4b71Sopenharmony_ci| -------- | -------- |
651e41f4b71Sopenharmony_ci| startAbilityByCall(want: Want): Promise&lt;Caller&gt; | 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-ability-kit/js-apis-inner-application-uiAbilityContext.md#abilitycontextstartabilitybycall) or **ServiceExtensionContext**.|
652e41f4b71Sopenharmony_ci| on(method: string, callback: CalleeCallBack): void | Callback invoked when the CalleeAbility registers a method.|
653e41f4b71Sopenharmony_ci| off(method: string): void | Callback invoked when the CalleeAbility deregisters a method.|
654e41f4b71Sopenharmony_ci| call(method: string, data: rpc.Parcelable): Promise&lt;void&gt; | Sends agreed parcelable data to the CalleeAbility.|
655e41f4b71Sopenharmony_ci| callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequence&gt; | Sends agreed parcelable data to the CalleeAbility and obtains the agreed parcelable data returned by the CalleeAbility.|
656e41f4b71Sopenharmony_ci| release(): void | Releases the caller object.|
657e41f4b71Sopenharmony_ci| on(type: "release", callback: OnReleaseCallback): void| Callback invoked when the caller object is released.|
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ciThe implementation of using the call for [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) interaction involves two parts:
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci- [Creating a CalleeAbility](#creating-a-calleeability)
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci- [Accessing the CalleeAbility](#accessing-the-calleeability)
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci### Creating a CalleeAbility
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ciFor the CalleeAbility, implement the callback to receive data and the methods to marshal and unmarshal data. When data needs to be received, use [on](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleeon) to register a listener. When data does not need to be received, use [off](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleeoff) to deregister the listener.
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_ci1. Configure the launch type of the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md).
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ci   For example, set the launch type of the CalleeAbility to **singleton**. For details, see [UIAbility Component Launch Type](uiability-launch-type.md).
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci2. Import the **UIAbility** module.
675e41f4b71Sopenharmony_ci
676e41f4b71Sopenharmony_ci   ```ts
677e41f4b71Sopenharmony_ci   import { UIAbility } from '@kit.AbilityKit';
678e41f4b71Sopenharmony_ci   ```
679e41f4b71Sopenharmony_ci
680e41f4b71Sopenharmony_ci3. Define the agreed parcelable data.
681e41f4b71Sopenharmony_ci
682e41f4b71Sopenharmony_ci   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.
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci    ```ts
686e41f4b71Sopenharmony_ci    import { rpc } from '@kit.IPCKit';
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ci    class MyParcelable {
689e41f4b71Sopenharmony_ci      num: number = 0;
690e41f4b71Sopenharmony_ci      str: string = '';
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci      constructor(num: number, string: string) {
693e41f4b71Sopenharmony_ci        this.num = num;
694e41f4b71Sopenharmony_ci        this.str = string;
695e41f4b71Sopenharmony_ci      }
696e41f4b71Sopenharmony_ci
697e41f4b71Sopenharmony_ci      mySequenceable(num: number, string: string): void {
698e41f4b71Sopenharmony_ci        this.num = num;
699e41f4b71Sopenharmony_ci        this.str = string;
700e41f4b71Sopenharmony_ci      }
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ci      marshalling(messageSequence: rpc.MessageSequence): boolean {
703e41f4b71Sopenharmony_ci        messageSequence.writeInt(this.num);
704e41f4b71Sopenharmony_ci        messageSequence.writeString(this.str);
705e41f4b71Sopenharmony_ci        return true;
706e41f4b71Sopenharmony_ci      }
707e41f4b71Sopenharmony_ci
708e41f4b71Sopenharmony_ci      unmarshalling(messageSequence: rpc.MessageSequence): boolean {
709e41f4b71Sopenharmony_ci        this.num = messageSequence.readInt();
710e41f4b71Sopenharmony_ci        this.str = messageSequence.readString();
711e41f4b71Sopenharmony_ci        return true;
712e41f4b71Sopenharmony_ci      }
713e41f4b71Sopenharmony_ci    }
714e41f4b71Sopenharmony_ci    ```
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci4. Implement [Callee.on](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleeon) and [Callee.off](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleeoff).
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci   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](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityoncreate) of the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) and deregistered in [onDestroy](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#uiabilityondestroy). 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:
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci    ```ts
722e41f4b71Sopenharmony_ci    import { AbilityConstant, UIAbility, Want, Caller } from '@kit.AbilityKit';
723e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
724e41f4b71Sopenharmony_ci    import { rpc } from '@kit.IPCKit';
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci    const MSG_SEND_METHOD: string = 'CallSendMsg';
727e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
728e41f4b71Sopenharmony_ci    const TAG: string = '[CalleeAbility]';
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci    class MyParcelable {
731e41f4b71Sopenharmony_ci      num: number = 0;
732e41f4b71Sopenharmony_ci      str: string = '';
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci      constructor(num: number, string: string) {
735e41f4b71Sopenharmony_ci        this.num = num;
736e41f4b71Sopenharmony_ci        this.str = string;
737e41f4b71Sopenharmony_ci      }
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci      mySequenceable(num: number, string: string): void {
740e41f4b71Sopenharmony_ci        this.num = num;
741e41f4b71Sopenharmony_ci        this.str = string;
742e41f4b71Sopenharmony_ci      }
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci      marshalling(messageSequence: rpc.MessageSequence): boolean {
745e41f4b71Sopenharmony_ci        messageSequence.writeInt(this.num);
746e41f4b71Sopenharmony_ci        messageSequence.writeString(this.str);
747e41f4b71Sopenharmony_ci        return true;
748e41f4b71Sopenharmony_ci      }
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci      unmarshalling(messageSequence: rpc.MessageSequence): boolean {
751e41f4b71Sopenharmony_ci        this.num = messageSequence.readInt();
752e41f4b71Sopenharmony_ci        this.str = messageSequence.readString();
753e41f4b71Sopenharmony_ci        return true;
754e41f4b71Sopenharmony_ci      }
755e41f4b71Sopenharmony_ci    }
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci    function sendMsgCallback(data: rpc.MessageSequence): rpc.Parcelable {
758e41f4b71Sopenharmony_ci      hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'CalleeSortFunc called');
759e41f4b71Sopenharmony_ci
760e41f4b71Sopenharmony_ci      // Obtain the parcelable data sent by the CallerAbility.
761e41f4b71Sopenharmony_ci      let receivedData: MyParcelable = new MyParcelable(0, '');
762e41f4b71Sopenharmony_ci      data.readParcelable(receivedData);
763e41f4b71Sopenharmony_ci      hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `receiveData[${receivedData.num}, ${receivedData.str}]`);
764e41f4b71Sopenharmony_ci      let num: number = receivedData.num;
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci      // Process the data.
767e41f4b71Sopenharmony_ci      // Return the parcelable data result to the CallerAbility.
768e41f4b71Sopenharmony_ci      return new MyParcelable(num + 1, `send ${receivedData.str} succeed`) as rpc.Parcelable;
769e41f4b71Sopenharmony_ci    }
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci    export default class CalleeAbility extends UIAbility {
772e41f4b71Sopenharmony_ci      caller: Caller | undefined;
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_ci      onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
775e41f4b71Sopenharmony_ci        try {
776e41f4b71Sopenharmony_ci          this.callee.on(MSG_SEND_METHOD, sendMsgCallback);
777e41f4b71Sopenharmony_ci        } catch (error) {
778e41f4b71Sopenharmony_ci          hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`);
779e41f4b71Sopenharmony_ci        }
780e41f4b71Sopenharmony_ci      }
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci      releaseCall(): void {
783e41f4b71Sopenharmony_ci        try {
784e41f4b71Sopenharmony_ci          if (this.caller) {
785e41f4b71Sopenharmony_ci            this.caller.release();
786e41f4b71Sopenharmony_ci            this.caller = undefined;
787e41f4b71Sopenharmony_ci          }
788e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'caller release succeed');
789e41f4b71Sopenharmony_ci        } catch (error) {
790e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `caller release failed with ${error}`);
791e41f4b71Sopenharmony_ci        }
792e41f4b71Sopenharmony_ci      }
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci      onDestroy(): void {
795e41f4b71Sopenharmony_ci        try {
796e41f4b71Sopenharmony_ci          this.callee.off(MSG_SEND_METHOD);
797e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Callee OnDestroy');
798e41f4b71Sopenharmony_ci          this.releaseCall();
799e41f4b71Sopenharmony_ci        } catch (error) {
800e41f4b71Sopenharmony_ci          hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`);
801e41f4b71Sopenharmony_ci        }
802e41f4b71Sopenharmony_ci      }
803e41f4b71Sopenharmony_ci    }
804e41f4b71Sopenharmony_ci    ```
805e41f4b71Sopenharmony_ci
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci### Accessing the CalleeAbility
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ci1. Import the [UIAbility](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md) module.
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci    ```ts
812e41f4b71Sopenharmony_ci    import { UIAbility } from '@kit.AbilityKit';
813e41f4b71Sopenharmony_ci    ```
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci2. Obtain the [Caller](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#caller) object.
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci   The [UIAbilityContext](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) attribute implements [startAbilityByCall](../reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall) to obtain the Caller object for communication. The following example uses **this.context** to obtain the UIAbilityContext, uses **startAbilityByCall** to start the CalleeAbility, obtain the Caller object, and register the [onRelease](../reference/apis-ability-kit/js-apis-app-ability-uiAbility.md#calleronrelease) listener of the CallerAbility. You need to implement processing based on service requirements.
818e41f4b71Sopenharmony_ci
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_ci    ```ts
821e41f4b71Sopenharmony_ci    import { common, Want, Caller } from '@kit.AbilityKit';
822e41f4b71Sopenharmony_ci    import { hilog } from '@kit.PerformanceAnalysisKit';
823e41f4b71Sopenharmony_ci    import { promptAction } from '@kit.ArkUI';
824e41f4b71Sopenharmony_ci    import { BusinessError } from '@kit.BasicServicesKit';
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ci    const TAG: string = '[Page_UIAbilityComponentsInteractive]';
827e41f4b71Sopenharmony_ci    const DOMAIN_NUMBER: number = 0xFF00;
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci    @Entry
830e41f4b71Sopenharmony_ci    @Component
831e41f4b71Sopenharmony_ci    struct Page_UIAbilityComponentsInteractive {
832e41f4b71Sopenharmony_ci      caller: Caller | undefined = undefined;
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ci      // Register the onRelease() listener of the CallerAbility.
835e41f4b71Sopenharmony_ci      private regOnRelease(caller: Caller): void {
836e41f4b71Sopenharmony_ci        hilog.info(DOMAIN_NUMBER, TAG, `caller is ${caller}`);
837e41f4b71Sopenharmony_ci        try {
838e41f4b71Sopenharmony_ci          caller.on('release', (msg: string) => {
839e41f4b71Sopenharmony_ci            hilog.info(DOMAIN_NUMBER, TAG, `caller onRelease is called ${msg}`);
840e41f4b71Sopenharmony_ci          })
841e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, 'succeeded in registering on release.');
842e41f4b71Sopenharmony_ci        } catch (err) {
843e41f4b71Sopenharmony_ci          let code = (err as BusinessError).code;
844e41f4b71Sopenharmony_ci          let message = (err as BusinessError).message;
845e41f4b71Sopenharmony_ci          hilog.error(DOMAIN_NUMBER, TAG, `Failed to caller register on release. Code is ${code}, message is ${message}`);
846e41f4b71Sopenharmony_ci        }
847e41f4b71Sopenharmony_ci      };
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_ci      build() {
850e41f4b71Sopenharmony_ci        Column() {
851e41f4b71Sopenharmony_ci          // ...
852e41f4b71Sopenharmony_ci          List({ initialIndex: 0 }) {
853e41f4b71Sopenharmony_ci            // ...
854e41f4b71Sopenharmony_ci            ListItem() {
855e41f4b71Sopenharmony_ci              Row() {
856e41f4b71Sopenharmony_ci                // ...
857e41f4b71Sopenharmony_ci              }
858e41f4b71Sopenharmony_ci              .onClick(() => {
859e41f4b71Sopenharmony_ci                let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
860e41f4b71Sopenharmony_ci                let want: Want = {
861e41f4b71Sopenharmony_ci                  bundleName: 'com.samples.stagemodelabilityinteraction',
862e41f4b71Sopenharmony_ci                  abilityName: 'CalleeAbility',
863e41f4b71Sopenharmony_ci                  parameters: {
864e41f4b71Sopenharmony_ci                    // Custom information.
865e41f4b71Sopenharmony_ci                    info: 'CallSendMsg'
866e41f4b71Sopenharmony_ci                  }
867e41f4b71Sopenharmony_ci                };
868e41f4b71Sopenharmony_ci                context.startAbilityByCall(want).then((caller: Caller) => {
869e41f4b71Sopenharmony_ci                  hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in starting ability.Code is ${caller}`);
870e41f4b71Sopenharmony_ci                  if (caller === undefined) {
871e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN_NUMBER, TAG, 'get caller failed');
872e41f4b71Sopenharmony_ci                    return;
873e41f4b71Sopenharmony_ci                  }
874e41f4b71Sopenharmony_ci                  else {
875e41f4b71Sopenharmony_ci                    hilog.info(DOMAIN_NUMBER, TAG, 'get caller success');
876e41f4b71Sopenharmony_ci                    this.regOnRelease(caller);
877e41f4b71Sopenharmony_ci                    promptAction.showToast({
878e41f4b71Sopenharmony_ci                      message: 'CallerSuccess'
879e41f4b71Sopenharmony_ci                    });
880e41f4b71Sopenharmony_ci                    try {
881e41f4b71Sopenharmony_ci                      caller.release();
882e41f4b71Sopenharmony_ci                    } catch (releaseErr) {
883e41f4b71Sopenharmony_ci                      console.log('Caller.release catch error, error.code: ' + JSON.stringify(releaseErr.code) +
884e41f4b71Sopenharmony_ci                        ' error.message: ' + JSON.stringify(releaseErr.message));
885e41f4b71Sopenharmony_ci                    }
886e41f4b71Sopenharmony_ci                  }
887e41f4b71Sopenharmony_ci                }).catch((err: BusinessError) => {
888e41f4b71Sopenharmony_ci                  hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`);
889e41f4b71Sopenharmony_ci                });
890e41f4b71Sopenharmony_ci              })
891e41f4b71Sopenharmony_ci            }
892e41f4b71Sopenharmony_ci            // ...
893e41f4b71Sopenharmony_ci          }
894e41f4b71Sopenharmony_ci          // ...
895e41f4b71Sopenharmony_ci        }
896e41f4b71Sopenharmony_ci        // ...
897e41f4b71Sopenharmony_ci      }
898e41f4b71Sopenharmony_ci    }
899e41f4b71Sopenharmony_ci    ```
900e41f4b71Sopenharmony_ci<!--DelEnd-->
901e41f4b71Sopenharmony_ci
902