• 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
572on(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| 401 | If the input parameter is not valid parameter. |
590| 16200001 | Caller released. The caller has been released. |
591
592For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
593
594**Example**
595
596  ```ts
597  let caller;
598  export default class MainAbility extends Ability {
599    onWindowStageCreate(windowStage) {
600      this.context.startAbilityByCall({
601        bundleName: 'com.example.myservice',
602        abilityName: 'MainAbility',
603        deviceId: ''
604      }).then((obj) => {
605          caller = obj;
606          try {
607            caller.on('release', (str) => {
608                console.log(' Caller OnRelease CallBack is called ' + str);
609            });
610          } catch (error) {
611            console.log('Caller.on catch error, error.code: ' + JSON.stringify(error.code) +
612              ' error.message: ' + JSON.stringify(error.message));
613          }
614      }).catch((err) => {
615        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
616          ' error.message: ' + JSON.stringify(err.message));
617      });
618    }
619  }
620  ```
621
622## Caller.off
623
624off(type: 'release', callback: OnReleaseCallback): void;
625
626Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved.
627
628**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
629
630**Parameters**
631
632| Name| Type| Mandatory| Description|
633| -------- | -------- | -------- | -------- |
634| type | string | Yes| Event type. The value is fixed at **release**.|
635| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.|
636
637**Error codes**
638
639| ID| Error Message|
640| ------- | -------------------------------- |
641| 401 | If the input parameter is not valid parameter. |
642For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
643
644**Example**
645
646  ```ts
647  let caller;
648  export default class MainUIAbility extends Ability {
649    onWindowStageCreate(windowStage) {
650      this.context.startAbilityByCall({
651        bundleName: 'com.example.myservice',
652        abilityName: 'MainUIAbility',
653        deviceId: ''
654      }).then((obj) => {
655          caller = obj;
656          try {
657            let onReleaseCallBack = (str) => {
658                console.log(' Caller OnRelease CallBack is called ' + str);
659            };
660            caller.on('release', onReleaseCallBack);
661            caller.off('release', onReleaseCallBack);
662          } catch (error) {
663            console.log('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
664              ' error.message: ' + JSON.stringify(error.message));
665          }
666      }).catch((err) => {
667        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
668          ' error.message: ' + JSON.stringify(err.message));
669      });
670    }
671  }
672  ```
673
674## Caller.off
675
676off(type: 'release'): void;
677
678Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved.
679
680**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
681
682**Parameters**
683
684| Name| Type| Mandatory| Description|
685| -------- | -------- | -------- | -------- |
686| type | string | Yes| Event type. The value is fixed at **release**.|
687
688**Error codes**
689
690| ID| Error Message|
691| ------- | -------------------------------- |
692| 401 | If the input parameter is not valid parameter. |
693For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
694
695**Example**
696
697  ```ts
698  let caller;
699  export default class MainUIAbility extends Ability {
700    onWindowStageCreate(windowStage) {
701      this.context.startAbilityByCall({
702        bundleName: 'com.example.myservice',
703        abilityName: 'MainUIAbility',
704        deviceId: ''
705      }).then((obj) => {
706          caller = obj;
707          try {
708            let onReleaseCallBack = (str) => {
709                console.log(' Caller OnRelease CallBack is called ' + str);
710            };
711            caller.on('release', onReleaseCallBack);
712            caller.off('release');
713          } catch (error) {
714            console.error('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
715              ' error.message: ' + JSON.stringify(error.message));
716          }
717      }).catch((err) => {
718        console.error('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
719          ' error.message: ' + JSON.stringify(err.message));
720      });
721    }
722  }
723  ```
724
725## Callee
726
727Implements callbacks for caller notification registration and deregistration.
728
729## Callee.on
730
731on(method: string, callback: CalleeCallback): void;
732
733Registers a caller notification callback, which is invoked when the target ability registers a function.
734
735**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
736
737**Parameters**
738
739  | Name| Type| Mandatory| Description|
740  | -------- | -------- | -------- | -------- |
741  | method | string | Yes| Notification message string negotiated between the two abilities.|
742  | 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.|
743
744**Error codes**
745
746| ID| Error Message|
747| ------- | -------------------------------- |
748| 16200004 | Method registered. The method has registered. |
749| 16000050 | Internal error. |
750
751For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
752
753**Example**
754
755  ```ts
756  class MyMessageAble{
757      name:''
758      str:''
759      num: 1
760      constructor(name, str) {
761        this.name = name;
762        this.str = str;
763      }
764      marshalling(messageSequence) {
765          messageSequence.writeInt(this.num);
766          messageSequence.writeString(this.str);
767          console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
768          return true;
769      }
770      unmarshalling(messageSequence) {
771          this.num = messageSequence.readInt();
772          this.str = messageSequence.readString();
773          console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
774          return true;
775      }
776  };
777  let method = 'call_Function';
778  function funcCallBack(pdata) {
779      console.log('Callee funcCallBack is called ' + pdata);
780      let msg = new MyMessageAble('test', '');
781      pdata.readParcelable(msg);
782      return new MyMessageAble('test1', 'Callee test');
783  }
784  export default class MainAbility extends Ability {
785    onCreate(want, launchParam) {
786      console.log('Callee onCreate is called');
787      try {
788        this.callee.on(method, funcCallBack);
789      } catch (error) {
790        console.log('Callee.on catch error, error.code: ' + JSON.stringify(error.code) +
791          ' error.message: ' + JSON.stringify(error.message));
792      }
793    }
794  }
795  ```
796
797## Callee.off
798
799off(method: string): void;
800
801Deregisters a caller notification callback, which is invoked when the target ability registers a function.
802
803**System capability**: SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore
804
805**Parameters**
806
807| Name| Type| Mandatory| Description|
808| -------- | -------- | -------- | -------- |
809| method | string | Yes| Registered notification message string.|
810
811**Error codes**
812
813| ID| Error Message|
814| ------- | -------------------------------- |
815| 16200005 | Method not registered. The method has not registered. |
816| 16000050 | Internal error. |
817
818For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
819
820
821**Example**
822
823  ```ts
824  let method = 'call_Function';
825  export default class MainAbility extends Ability {
826    onCreate(want, launchParam) {
827      console.log('Callee onCreate is called');
828      try {
829        this.callee.off(method);
830      } catch (error) {
831        console.log('Callee.off catch error, error.code: ' + JSON.stringify(error.code) +
832          ' error.message: ' + JSON.stringify(error.message));
833      }
834    }
835  }
836  ```
837
838## OnReleaseCallback
839
840(msg: string): void;
841
842**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
843
844| Name| Readable| Writable| Type| Description|
845| -------- | -------- | -------- | -------- | -------- |
846| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.|
847
848## CalleeCallback
849
850(indata: rpc.MessageSequence): rpc.Parcelable;
851
852**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
853
854| Name| Readable| Writable| Type| Description|
855| -------- | -------- | -------- | -------- | -------- |
856| (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.|
857