• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.UIAbility (UIAbility)
2
3UIAbility is an application component that has the UI. The **UIAbility** module provides lifecycle callback such as component creation, destruction, and foreground/background switching. It also provides the following capabilities related to component collaboration:
4
5- [Caller](#caller): an object returned by [startAbilityByCall](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall). The CallerAbility (caller) uses this object to communicate with the CalleeAbility (callee).
6- [Callee](#callee): an internal object of UIAbility. The CalleeAbility (callee) uses this object to communicate with the CallerAbility (caller).
7
8> **NOTE**
9>
10> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
11> The APIs of this module can be used only in the stage model.
12
13## Modules to Import
14
15```ts
16import Ability from '@ohos.app.ability.UIAbility';
17```
18
19## Attributes
20
21**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
22
23| Name| Type| Readable| Writable| Description|
24| -------- | -------- | -------- | -------- | -------- |
25| context | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | Yes| No| Context of the UIAbility.|
26| launchWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters for starting the UIAbility.|
27| lastRequestWant | [Want](js-apis-app-ability-want.md) | Yes| No| Parameters used when the UIAbility was started last time.|
28| callee | [Callee](#callee) | Yes| No| Object that invokes the stub service.|
29
30## UIAbility.onCreate
31
32onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
33
34Called to initialize the service logic when an ability is created.
35
36**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
37
38**Parameters**
39
40| Name| Type| Mandatory| Description|
41| -------- | -------- | -------- | -------- |
42| want | [Want](js-apis-app-ability-want.md) | Yes| Information related to this UIAbility, including the ability name and bundle name.|
43| param | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
44
45**Example**
46
47  ```ts
48  class myAbility extends Ability {
49      onCreate(want, param) {
50          console.log('onCreate, want:' + want.abilityName);
51      }
52  }
53  ```
54
55
56## UIAbility.onWindowStageCreate
57
58onWindowStageCreate(windowStage: window.WindowStage): void
59
60Called when a **WindowStage** is created for this UIAbility.
61
62**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
63
64**Parameters**
65
66| Name| Type| Mandatory| Description|
67| -------- | -------- | -------- | -------- |
68| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
69
70**Example**
71
72  ```ts
73  class myAbility extends Ability {
74      onWindowStageCreate(windowStage) {
75          console.log('onWindowStageCreate');
76      }
77  }
78  ```
79
80
81## UIAbility.onWindowStageDestroy
82
83onWindowStageDestroy(): void
84
85Called when the **WindowStage** is destroyed for this UIAbility.
86
87**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
88
89**Example**
90
91  ```ts
92  class myAbility extends Ability {
93      onWindowStageDestroy() {
94          console.log('onWindowStageDestroy');
95      }
96  }
97  ```
98
99
100## UIAbility.onWindowStageRestore
101
102onWindowStageRestore(windowStage: window.WindowStage): void
103
104Called when the **WindowStage** is restored during the migration of this UIAbility, which is a multi-instance ability.
105
106**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
107
108**Parameters**
109
110| Name| Type| Mandatory| Description|
111| -------- | -------- | -------- | -------- |
112| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | Yes| **WindowStage** information.|
113
114**Example**
115
116  ```ts
117  class myAbility extends Ability {
118      onWindowStageRestore(windowStage) {
119          console.log('onWindowStageRestore');
120      }
121  }
122  ```
123
124
125## UIAbility.onDestroy
126
127onDestroy(): void | Promise<void>;
128
129Called when this ability is destroyed to clear resources.
130
131**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
132
133**Example**
134
135  ```ts
136  class myAbility extends Ability {
137      onDestroy() {
138          console.log('onDestroy');
139      }
140  }
141  ```
142
143
144## UIAbility.onForeground
145
146onForeground(): void;
147
148Called when this ability is switched from the background to the foreground.
149
150**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
151
152**Example**
153
154  ```ts
155  class myAbility extends Ability {
156      onForeground() {
157          console.log('onForeground');
158      }
159  }
160  ```
161
162
163## UIAbility.onBackground
164
165onBackground(): void;
166
167Called when this ability is switched from the foreground to the background.
168
169**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
170
171**Example**
172
173  ```ts
174  class myAbility extends Ability {
175      onBackground() {
176          console.log('onBackground');
177      }
178  }
179  ```
180
181
182## UIAbility.onContinue
183
184onContinue(wantParam: { [key: string]: Object }): AbilityConstant.OnContinueResult;
185
186Called to save data during the ability migration preparation process.
187
188**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
189
190**Parameters**
191
192| Name| Type| Mandatory| Description|
193| -------- | -------- | -------- | -------- |
194| wantParam | {[key: string]: any} | Yes| **want** parameter.|
195
196**Return value**
197
198| Type| Description|
199| -------- | -------- |
200| [AbilityConstant.OnContinueResult](js-apis-app-ability-abilityConstant.md#abilityconstantoncontinueresult) | Continuation result.|
201
202**Example**
203
204  ```ts
205  import AbilityConstant from '@ohos.app.ability.AbilityConstant';
206  class MyUIAbility extends Ability {
207      onContinue(wantParams) {
208          console.log('onContinue');
209          wantParams['myData'] = 'my1234567';
210          return AbilityConstant.OnContinueResult.AGREE;
211      }
212  }
213  ```
214
215
216## UIAbility.onNewWant
217
218onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void;
219
220Called when a new Want is passed in and this UIAbility is started again.
221
222**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
223
224**Parameters**
225
226| Name| Type| Mandatory| Description|
227| -------- | -------- | -------- | -------- |
228| want | [Want](js-apis-app-ability-want.md) | Yes| Want information, such as the ability name and bundle name.|
229| launchParams | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | Yes| Reason for the UIAbility startup and the last abnormal exit.|
230
231**Example**
232
233  ```ts
234   class MyUIAbility extends Ability {
235      onNewWant(want, launchParams) {
236          console.log('onNewWant, want:' + want.abilityName);
237          console.log('onNewWant, launchParams:' + JSON.stringify(launchParams));
238       }
239   }
240  ```
241
242## UIAbility.onDump
243
244onDump(params: Array\<string>): Array\<string>;
245
246Dumps client information.
247
248**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
249
250**Parameters**
251
252| Name| Type| Mandatory| Description|
253| -------- | -------- | -------- | -------- |
254| params | Array\<string> | Yes| Parameters in the form of a command.|
255
256**Example**
257
258  ```ts
259  class myAbility extends Ability {
260      onDump(params) {
261          console.log('dump, params:' + JSON.stringify(params));
262          return ['params'];
263      }
264  }
265  ```
266
267
268## UIAbility.onSaveState
269
270onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;
271
272Called when the framework automatically saves the UIAbility state in the case of an application fault. This API is used together with [appRecovery](js-apis-app-ability-appRecovery.md). If automatic state saving is enabled, **onSaveState** is called to save the state of this ability.
273
274**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
275
276**Parameters**
277
278| Name| Type| Mandatory| Description|
279| -------- | -------- | -------- | -------- |
280| reason | [AbilityConstant.StateType](js-apis-app-ability-abilityConstant.md#abilityconstantstatetype) | Yes| Reason for triggering the callback to save the UIAbility state.|
281| wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.|
282
283**Return value**
284
285| Type| Description|
286| -------- | -------- |
287| AbilityConstant.OnSaveResult | Whether the ability state is saved.|
288
289**Example**
290
291  ```ts
292import AbilityConstant from '@ohos.app.ability.AbilityConstant';
293
294class MyUIAbility extends Ability {
295    onSaveState(reason, wantParam) {
296        console.log('onSaveState');
297        wantParam['myData'] = 'my1234567';
298        return AbilityConstant.OnSaveResult.RECOVERY_AGREE;
299    }
300}
301  ```
302
303
304
305## Caller
306
307Implements sending of parcelable data to the target ability when the CallerAbility invokes the target ability (CalleeAbility).
308
309## Caller.call
310
311call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;;
312
313Sends parcelable data to the target ability.
314
315**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
316
317**Parameters**
318
319  | Name| Type| Mandatory| Description|
320  | -------- | -------- | -------- | -------- |
321  | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the parcelable data.|
322  | data | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | Yes| Parcelable data. You need to customize the data.|
323
324**Return value**
325
326| Type| Description|
327| -------- | -------- |
328| Promise&lt;void&gt; | Promise used to return a response.|
329
330**Error codes**
331
332| ID| Error Message|
333| ------- | -------------------------------- |
334| 16200001 | Caller released. The caller has been released. |
335| 16200002 | Callee invalid. The callee does not exist. |
336| 16000050 | Internal Error. |
337
338For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
339
340**Example**
341
342  ```ts
343  class MyMessageAble{ // Custom parcelable data structure.
344    name:''
345    str:''
346    num: 1
347    constructor(name, str) {
348      this.name = name;
349      this.str = str;
350    }
351    marshalling(messageSequence) {
352      messageSequence.writeInt(this.num);
353      messageSequence.writeString(this.str);
354      console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
355      return true;
356    }
357    unmarshalling(messageSequence) {
358      this.num = messageSequence.readInt();
359      this.str = messageSequence.readString();
360      console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
361      return true;
362    }
363  };
364  let method = 'call_Function'; // Notification message string negotiated by the two abilities.
365  let caller;
366  export default class MainAbility extends Ability {
367    onWindowStageCreate(windowStage) {
368      this.context.startAbilityByCall({
369        bundleName: 'com.example.myservice',
370        abilityName: 'MainAbility',
371        deviceId: ''
372      }).then((obj) => {
373        caller = obj;
374        let msg = new MyMessageAble('msg', 'world'); // See the definition of Parcelable.
375        caller.call(method, msg)
376          .then(() => {
377            console.log('Caller call() called');
378          })
379          .catch((callErr) => {
380            console.log('Caller.call catch error, error.code: ' + JSON.stringify(callErr.code) +
381              ' error.message: ' + JSON.stringify(callErr.message));
382          });
383      }).catch((err) => {
384        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
385          ' error.message: ' + JSON.stringify(err.message));
386      });
387    }
388  }
389  ```
390
391
392## Caller.callWithResult
393
394callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequence&gt;;
395
396Sends parcelable data to the target ability and obtains the parcelable data returned by the target ability.
397
398**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
399
400**Parameters**
401
402  | Name| Type| Mandatory| Description|
403  | -------- | -------- | -------- | -------- |
404  | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the parcelable data.|
405  | data | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | Yes| Parcelable data. You need to customize the data.|
406
407**Return value**
408
409  | Type| Description|
410  | -------- | -------- |
411  | Promise&lt;[rpc.MessageSequence](js-apis-rpc.md#messagesequence9)&gt; | Promise used to return the parcelable data from the target ability.|
412
413**Error codes**
414
415| ID| Error Message|
416| ------- | -------------------------------- |
417| 16200001 | Caller released. The caller has been released. |
418| 16200002 | Callee invalid. The callee does not exist. |
419| 16000050 | Internal Error. |
420
421For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
422
423**Example**
424
425  ```ts
426  class MyMessageAble{
427    name:''
428    str:''
429    num: 1
430    constructor(name, str) {
431      this.name = name;
432      this.str = str;
433    }
434    marshalling(messageSequence) {
435      messageSequence.writeInt(this.num);
436      messageSequence.writeString(this.str);
437      console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
438      return true;
439    }
440    unmarshalling(messageSequence) {
441      this.num = messageSequence.readInt();
442      this.str = messageSequence.readString();
443      console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
444      return true;
445    }
446  };
447  let method = 'call_Function';
448  let caller;
449  export default class MainAbility extends Ability {
450    onWindowStageCreate(windowStage) {
451      this.context.startAbilityByCall({
452        bundleName: 'com.example.myservice',
453        abilityName: 'MainAbility',
454        deviceId: ''
455      }).then((obj) => {
456        caller = obj;
457        let msg = new MyMessageAble(1, 'world');
458        caller.callWithResult(method, msg)
459          .then((data) => {
460            console.log('Caller callWithResult() called');
461            let retmsg = new MyMessageAble(0, '');
462            data.readParcelable(retmsg);
463          })
464          .catch((callErr) => {
465            console.log('Caller.callWithResult catch error, error.code: ' + JSON.stringify(callErr.code) +
466              ' error.message: ' + JSON.stringify(callErr.message));
467          });
468      }).catch((err) => {
469        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
470          ' error.message: ' + JSON.stringify(err.message));
471      });
472    }
473  }
474  ```
475
476
477## Caller.release
478
479release(): void;
480
481Releases the caller interface of the target ability.
482
483**System capability**: SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore
484
485**Error codes**
486
487| ID| Error Message|
488| ------- | -------------------------------- |
489| 16200001 | Caller released. The caller has been released. |
490| 16200002 | Callee invalid. The callee does not exist. |
491
492For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
493
494**Example**
495
496  ```ts
497  let caller;
498  export default class MainAbility extends Ability {
499    onWindowStageCreate(windowStage) {
500      this.context.startAbilityByCall({
501        bundleName: 'com.example.myservice',
502        abilityName: 'MainAbility',
503        deviceId: ''
504      }).then((obj) => {
505        caller = obj;
506        try {
507          caller.release();
508        } catch (releaseErr) {
509          console.log('Caller.release catch error, error.code: ' + JSON.stringify(releaseErr.code) +
510            ' error.message: ' + JSON.stringify(releaseErr.message));
511        }
512      }).catch((err) => {
513        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
514          ' error.message: ' + JSON.stringify(err.message));
515      });
516    }
517  }
518  ```
519
520## Caller.onRelease
521
522 onRelease(callback: OnReleaseCallback): void;
523
524Registers a callback that is invoked when the stub on the target ability is disconnected.
525
526**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
527
528**Error codes**
529
530| ID| Error Message|
531| ------- | -------------------------------- |
532| 16200001 | Caller released. The caller has been released. |
533
534For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
535
536**Parameters**
537
538| Name| Type| Mandatory| Description|
539| -------- | -------- | -------- | -------- |
540| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
541
542**Example**
543
544  ```ts
545  let caller;
546  export default class MainAbility extends Ability {
547    onWindowStageCreate(windowStage) {
548      this.context.startAbilityByCall({
549        bundleName: 'com.example.myservice',
550        abilityName: 'MainAbility',
551        deviceId: ''
552      }).then((obj) => {
553          caller = obj;
554          try {
555            caller.onRelease((str) => {
556                console.log(' Caller OnRelease CallBack is called ' + str);
557            });
558          } catch (error) {
559            console.log('Caller.onRelease catch error, error.code: ' + JSON.stringify(error.code) +
560              ' error.message: ' + JSON.stringify(error.message));
561          }
562      }).catch((err) => {
563        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
564          ' error.message: ' + JSON.stringify(err.message));
565      });
566    }
567  }
568  ```
569
570## Caller.on
571
572 on(type: 'release', callback: OnReleaseCallback): void;
573
574Registers a callback that is invoked when the stub on the target ability is disconnected.
575
576**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
577
578**Parameters**
579
580| Name| Type| Mandatory| Description|
581| -------- | -------- | -------- | -------- |
582| type | string | Yes| Event type. The value is fixed at **release**.|
583| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
584
585**Error codes**
586
587| ID| Error Message|
588| ------- | -------------------------------- |
589| 16200001 | Caller released. The caller has been released. |
590
591For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
592
593**Example**
594
595  ```ts
596  let caller;
597  export default class MainAbility extends Ability {
598    onWindowStageCreate(windowStage) {
599      this.context.startAbilityByCall({
600        bundleName: 'com.example.myservice',
601        abilityName: 'MainAbility',
602        deviceId: ''
603      }).then((obj) => {
604          caller = obj;
605          try {
606            caller.on('release', (str) => {
607                console.log(' Caller OnRelease CallBack is called ' + str);
608            });
609          } catch (error) {
610            console.log('Caller.on catch error, error.code: ' + JSON.stringify(error.code) +
611              ' error.message: ' + JSON.stringify(error.message));
612          }
613      }).catch((err) => {
614        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
615          ' error.message: ' + JSON.stringify(err.message));
616      });
617    }
618  }
619  ```
620
621## Caller.off
622
623off(type: 'release', callback: OnReleaseCallback): void;
624
625Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved.
626
627**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
628
629**Parameters**
630
631| Name| Type| Mandatory| Description|
632| -------- | -------- | -------- | -------- |
633| type | string | Yes| Event type. The value is fixed at **release**.|
634| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
635
636**Error codes**
637
638| ID| Error Message|
639| ------- | -------------------------------- |
640| 401 | If the input parameter is not valid parameter. |
641For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
642
643**Example**
644
645  ```ts
646  let caller;
647  export default class MainUIAbility extends Ability {
648    onWindowStageCreate(windowStage) {
649      this.context.startAbilityByCall({
650        bundleName: 'com.example.myservice',
651        abilityName: 'MainUIAbility',
652        deviceId: ''
653      }).then((obj) => {
654          caller = obj;
655          try {
656            let onReleaseCallBack = (str) => {
657                console.log(' Caller OnRelease CallBack is called ' + str);
658            };
659            caller.on('release', onReleaseCallBack);
660            caller.off('release', onReleaseCallBack);
661          } catch (error) {
662            console.log('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
663              ' error.message: ' + JSON.stringify(error.message));
664          }
665      }).catch((err) => {
666        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
667          ' error.message: ' + JSON.stringify(err.message));
668      });
669    }
670  }
671  ```
672
673## Caller.off
674
675off(type: 'release'): void;
676
677Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved.
678
679**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
680
681**Parameters**
682
683| Name| Type| Mandatory| Description|
684| -------- | -------- | -------- | -------- |
685| type | string | Yes| Event type. The value is fixed at **release**.|
686
687**Error codes**
688
689| ID| Error Message|
690| ------- | -------------------------------- |
691| 401 | If the input parameter is not valid parameter. |
692For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
693
694**Example**
695
696  ```ts
697  let caller;
698  export default class MainUIAbility extends Ability {
699    onWindowStageCreate(windowStage) {
700      this.context.startAbilityByCall({
701        bundleName: 'com.example.myservice',
702        abilityName: 'MainUIAbility',
703        deviceId: ''
704      }).then((obj) => {
705          caller = obj;
706          try {
707            let onReleaseCallBack = (str) => {
708                console.log(' Caller OnRelease CallBack is called ' + str);
709            };
710            caller.on('release', onReleaseCallBack);
711            caller.off('release');
712          } catch (error) {
713            console.error('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
714              ' error.message: ' + JSON.stringify(error.message));
715          }
716      }).catch((err) => {
717        console.error('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
718          ' error.message: ' + JSON.stringify(err.message));
719      });
720    }
721  }
722  ```
723
724## Callee
725
726Implements callbacks for caller notification registration and deregistration.
727
728## Callee.on
729
730on(method: string, callback: CalleeCallback): void;
731
732Registers a caller notification callback, which is invoked when the target ability registers a function.
733
734**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
735
736**Parameters**
737
738  | Name| Type| Mandatory| Description|
739  | -------- | -------- | -------- | -------- |
740  | method | string | Yes| Notification message string negotiated between the two abilities.|
741  | callback | [CalleeCallback](#calleecallback) | Yes| JS notification synchronization callback of the [rpc.MessageSequence](js-apis-rpc.md#messagesequence9) type. The callback must return at least one empty [rpc.Parcelable](js-apis-rpc.md#parcelable9) object. Otherwise, the function execution fails.|
742
743**Error codes**
744
745| ID| Error Message|
746| ------- | -------------------------------- |
747| 16200004 | Method registered. The method has registered. |
748| 16000050 | Internal error. |
749
750For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
751
752**Example**
753
754  ```ts
755  class MyMessageAble{
756      name:''
757      str:''
758      num: 1
759      constructor(name, str) {
760        this.name = name;
761        this.str = str;
762      }
763      marshalling(messageSequence) {
764          messageSequence.writeInt(this.num);
765          messageSequence.writeString(this.str);
766          console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
767          return true;
768      }
769      unmarshalling(messageSequence) {
770          this.num = messageSequence.readInt();
771          this.str = messageSequence.readString();
772          console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
773          return true;
774      }
775  };
776  let method = 'call_Function';
777  function funcCallBack(pdata) {
778      console.log('Callee funcCallBack is called ' + pdata);
779      let msg = new MyMessageAble('test', '');
780      pdata.readParcelable(msg);
781      return new MyMessageAble('test1', 'Callee test');
782  }
783  export default class MainAbility extends Ability {
784    onCreate(want, launchParam) {
785      console.log('Callee onCreate is called');
786      try {
787        this.callee.on(method, funcCallBack);
788      } catch (error) {
789        console.log('Callee.on catch error, error.code: ' + JSON.stringify(error.code) +
790          ' error.message: ' + JSON.stringify(error.message));
791      }
792    }
793  }
794  ```
795
796## Callee.off
797
798off(method: string): void;
799
800Deregisters a caller notification callback, which is invoked when the target ability registers a function.
801
802**System capability**: SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore
803
804**Parameters**
805
806| Name| Type| Mandatory| Description|
807| -------- | -------- | -------- | -------- |
808| method | string | Yes| Registered notification message string.|
809
810**Error codes**
811
812| ID| Error Message|
813| ------- | -------------------------------- |
814| 16200005 | Method not registered. The method has not registered. |
815| 16000050 | Internal error. |
816
817For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
818
819
820**Example**
821
822  ```ts
823  let method = 'call_Function';
824  export default class MainAbility extends Ability {
825    onCreate(want, launchParam) {
826      console.log('Callee onCreate is called');
827      try {
828        this.callee.off(method);
829      } catch (error) {
830        console.log('Callee.off catch error, error.code: ' + JSON.stringify(error.code) +
831          ' error.message: ' + JSON.stringify(error.message));
832      }
833    }
834  }
835  ```
836
837## OnReleaseCallback
838
839(msg: string): void;
840
841**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
842
843| Name| Readable| Writable| Type| Description|
844| -------- | -------- | -------- | -------- | -------- |
845| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.|
846
847## CalleeCallback
848
849(indata: rpc.MessageSequence): rpc.Parcelable;
850
851**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
852
853| Name| Readable| Writable| Type| Description|
854| -------- | -------- | -------- | -------- | -------- |
855| (indata: [rpc.MessageSequence](js-apis-rpc.md#messagesequence9)) | Yes| No| [rpc.Parcelable](js-apis-rpc.md#parcelable9) | Prototype of the listener function registered by the callee.|
856