• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.UIAbility (UIAbility)
2
3UIAbility是包含UI界面的应用组件,提供组件创建、销毁、前后台切换等生命周期回调,同时也具备组件协同的能力,组件协同主要提供如下常用功能:
4
5- [Caller](#caller):由[startAbilityByCall](js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartabilitybycall)接口返回,CallerAbility(调用者)可使用Caller与CalleeAbility(被调用者)进行通信。
6- [Callee](#callee):UIAbility的内部对象,CalleeAbility(被调用者)可以通过Callee与Caller进行通信。
7
8> **说明:**
9>
10> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
11> 本模块接口仅可在Stage模型下使用。
12
13## 导入模块
14
15```ts
16import Ability from '@ohos.app.ability.UIAbility';
17```
18
19## 属性
20
21**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.AbilityCore
22
23| 名称 | 类型 | 可读 | 可写 | 说明 |
24| -------- | -------- | -------- | -------- | -------- |
25| context | [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) | 是 | 否 | 上下文。 |
26| launchWant | [Want](js-apis-app-ability-want.md) | 是 | 否 | UIAbility启动时的参数。 |
27| lastRequestWant | [Want](js-apis-app-ability-want.md) | 是 | 否 | UIAbility最后请求时的参数。 |
28| callee | [Callee](#callee) | 是 | 否 | 调用Stub(桩)服务对象。|
29
30## UIAbility.onCreate
31
32onCreate(want: Want, param: AbilityConstant.LaunchParam): void;
33
34Ability创建时回调,执行初始化业务逻辑操作。
35
36**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
37
38**参数:**
39
40| 参数名 | 类型 | 必填 | 说明 |
41| -------- | -------- | -------- | -------- |
42| want | [Want](js-apis-app-ability-want.md) | 是 | 当前UIAbility的Want类型信息,包括ability名称、bundle名称等。 |
43| param | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | 创建UIAbility、上次异常退出的原因信息。 |
44
45**示例:**
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
60当WindowStage创建后调用。
61
62**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
63
64**参数:**
65
66| 参数名 | 类型 | 必填 | 说明 |
67| -------- | -------- | -------- | -------- |
68| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | WindowStage相关信息。 |
69
70**示例:**
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
85当WindowStage销毁后调用。
86
87**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
88
89**示例:**
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
104当迁移多实例ability时,恢复WindowStage后调用。
105
106**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
107
108**参数:**
109
110| 参数名 | 类型 | 必填 | 说明 |
111| -------- | -------- | -------- | -------- |
112| windowStage | [window.WindowStage](js-apis-window.md#windowstage9) | 是 | WindowStage相关信息。 |
113
114**示例:**
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
129Ability生命周期回调,在销毁时回调,执行资源清理等操作。
130
131**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
132
133**示例:**
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
148Ability生命周期回调,当应用从后台转到前台时触发。
149
150**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
151
152**示例:**
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
167Ability生命周期回调,当应用从前台转到后台时触发。
168
169**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
170
171**示例:**
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
186当ability迁移准备迁移时触发,保存数据。
187
188**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
189
190**参数:**
191
192| 参数名 | 类型 | 必填 | 说明 |
193| -------- | -------- | -------- | -------- |
194| wantParam | {[key: string]: any} | 是 | want相关参数。 |
195
196**返回值:**
197
198| 类型 | 说明 |
199| -------- | -------- |
200| [AbilityConstant.OnContinueResult](js-apis-app-ability-abilityConstant.md#abilityconstantoncontinueresult) | 继续的结果。 |
201
202**示例:**
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
220当传入新的Want,ability再次被拉起时会回调执行该方法。
221
222**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
223
224**参数:**
225
226| 参数名 | 类型 | 必填 | 说明 |
227| -------- | -------- | -------- | -------- |
228| want | [Want](js-apis-app-ability-want.md) | 是 | Want类型参数,如ability名称,包名等。 |
229| launchParams | [AbilityConstant.LaunchParam](js-apis-app-ability-abilityConstant.md#abilityconstantlaunchparam) | 是 | UIAbility启动的原因、上次异常退出的原因信息。 |
230
231**示例:**
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
246转储客户端信息时调用。
247
248**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
249
250**参数:**
251
252| 参数名 | 类型 | 必填 | 说明 |
253| -------- | -------- | -------- | -------- |
254| params | Array\<string> | 是 | 表示命令形式的参数。|
255
256**示例:**
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
272该API配合[appRecovery](js-apis-app-ability-appRecovery.md)使用。在应用故障时,如果使能了自动保存状态,框架将回调onSaveState保存Ability状态。
273
274**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
275
276**参数:**
277
278| 参数名 | 类型 | 必填 | 说明 |
279| -------- | -------- | -------- | -------- |
280| reason | [AbilityConstant.StateType](js-apis-app-ability-abilityConstant.md#abilityconstantstatetype) | 是 | 回调保存状态的原因。 |
281| wantParam | {[key:&nbsp;string]:&nbsp;any} | 是 | want相关参数。 |
282
283**返回值:**
284
285| 类型 | 说明 |
286| -------- | -------- |
287| AbilityConstant.OnSaveResult | 是否同意保存当前Ability的状态。 |
288
289**示例:**
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
307通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
308
309## Caller.call
310
311call(method: string, data: rpc.Parcelable): Promise&lt;void&gt;;
312
313向通用组件服务端发送约定序列化数据。
314
315**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
316
317**参数:**
318
319  | 参数名 | 类型 | 必填 | 说明 |
320  | -------- | -------- | -------- | -------- |
321  | method | string | 是 | 约定的服务端注册事件字符串。 |
322  | data | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | 是 | 由开发者实现的Parcelable可序列化数据。 |
323
324**返回值:**
325
326| 类型 | 说明 |
327| -------- | -------- |
328| Promise&lt;void&gt; | Promise形式返回应答。 |
329
330**错误码:**
331
332| 错误码ID | 错误信息 |
333| ------- | -------------------------------- |
334| 401 | If the input parameter is not valid parameter. |
335其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
336
337**示例:**
338
339  ```ts
340  class MyMessageAble{ // 自定义的Parcelable数据结构
341    name:''
342    str:''
343    num: 1
344    constructor(name, str) {
345      this.name = name;
346      this.str = str;
347    }
348    marshalling(messageSequence) {
349      messageSequence.writeInt(this.num);
350      messageSequence.writeString(this.str);
351      console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
352      return true;
353    }
354    unmarshalling(messageSequence) {
355      this.num = messageSequence.readInt();
356      this.str = messageSequence.readString();
357      console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
358      return true;
359    }
360  };
361  let method = 'call_Function'; // 约定的通知消息字符串
362  let caller;
363  export default class MainAbility extends Ability {
364    onWindowStageCreate(windowStage) {
365      this.context.startAbilityByCall({
366        bundleName: 'com.example.myservice',
367        abilityName: 'MainAbility',
368        deviceId: ''
369      }).then((obj) => {
370        caller = obj;
371        let msg = new MyMessageAble('msg', 'world'); // 参考Parcelable数据定义
372        caller.call(method, msg)
373          .then(() => {
374            console.log('Caller call() called');
375          })
376          .catch((callErr) => {
377            console.log('Caller.call catch error, error.code: ' + JSON.stringify(callErr.code) +
378              ' error.message: ' + JSON.stringify(callErr.message));
379          });
380      }).catch((err) => {
381        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
382          ' error.message: ' + JSON.stringify(err.message));
383      });
384    }
385  }
386  ```
387
388
389## Caller.callWithResult
390
391callWithResult(method: string, data: rpc.Parcelable): Promise&lt;rpc.MessageSequence&gt;;
392
393向通用组件服务端发送约定序列化数据, 并将服务端返回的约定序列化数据带回。
394
395**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
396
397**参数:**
398
399  | 参数名 | 类型 | 必填 | 说明 |
400  | -------- | -------- | -------- | -------- |
401  | method | string | 是 | 约定的服务端注册事件字符串。 |
402  | data | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | 是 | 由开发者实现的Parcelable可序列化数据。 |
403
404**返回值:**
405
406  | 类型 | 说明 |
407  | -------- | -------- |
408  | Promise&lt;[rpc.MessageSequence](js-apis-rpc.md#messagesequence9)&gt; | Promise形式返回通用组件服务端应答数据。 |
409
410**错误码:**
411
412| 错误码ID | 错误信息 |
413| ------- | -------------------------------- |
414| 401 | If the input parameter is not valid parameter. |
415其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
416
417**示例:**
418
419  ```ts
420  class MyMessageAble{
421    name:''
422    str:''
423    num: 1
424    constructor(name, str) {
425      this.name = name;
426      this.str = str;
427    }
428    marshalling(messageSequence) {
429      messageSequence.writeInt(this.num);
430      messageSequence.writeString(this.str);
431      console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
432      return true;
433    }
434    unmarshalling(messageSequence) {
435      this.num = messageSequence.readInt();
436      this.str = messageSequence.readString();
437      console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
438      return true;
439    }
440  };
441  let method = 'call_Function';
442  let caller;
443  export default class MainAbility extends Ability {
444    onWindowStageCreate(windowStage) {
445      this.context.startAbilityByCall({
446        bundleName: 'com.example.myservice',
447        abilityName: 'MainAbility',
448        deviceId: ''
449      }).then((obj) => {
450        caller = obj;
451        let msg = new MyMessageAble(1, 'world');
452        caller.callWithResult(method, msg)
453          .then((data) => {
454            console.log('Caller callWithResult() called');
455            let retmsg = new MyMessageAble(0, '');
456            data.readParcelable(retmsg);
457          })
458          .catch((callErr) => {
459            console.log('Caller.callWithResult catch error, error.code: ' + JSON.stringify(callErr.code) +
460              ' error.message: ' + JSON.stringify(callErr.message));
461          });
462      }).catch((err) => {
463        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
464          ' error.message: ' + JSON.stringify(err.message));
465      });
466    }
467  }
468  ```
469
470
471## Caller.release
472
473release(): void;
474
475主动释放通用组件服务端的通信接口。
476
477**系统能力**:SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore
478
479**错误码:**
480
481| 错误码ID | 错误信息 |
482| ------- | -------------------------------- |
483| 401 | Invalid input parameter. |
484| 16200001 | Caller released. The caller has been released. |
485| 16200002 | Callee invalid. The callee does not exist. |
486| 16000050 | Internal Error. |
487
488**示例:**
489
490  ```ts
491  let caller;
492  export default class MainAbility extends Ability {
493    onWindowStageCreate(windowStage) {
494      this.context.startAbilityByCall({
495        bundleName: 'com.example.myservice',
496        abilityName: 'MainAbility',
497        deviceId: ''
498      }).then((obj) => {
499        caller = obj;
500        try {
501          caller.release();
502        } catch (releaseErr) {
503          console.log('Caller.release catch error, error.code: ' + JSON.stringify(releaseErr.code) +
504            ' error.message: ' + JSON.stringify(releaseErr.message));
505        }
506      }).catch((err) => {
507        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
508          ' error.message: ' + JSON.stringify(err.message));
509      });
510    }
511  }
512  ```
513
514## Caller.onRelease
515
516 onRelease(callback: OnReleaseCallback): void;
517
518注册通用组件服务端Stub(桩)断开监听通知。
519
520**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
521
522**参数:**
523
524| 参数名 | 类型 | 必填 | 说明 |
525| -------- | -------- | -------- | -------- |
526| callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回onRelease回调结果。 |
527
528**示例:**
529
530  ```ts
531  let caller;
532  export default class MainAbility extends Ability {
533    onWindowStageCreate(windowStage) {
534      this.context.startAbilityByCall({
535        bundleName: 'com.example.myservice',
536        abilityName: 'MainAbility',
537        deviceId: ''
538      }).then((obj) => {
539          caller = obj;
540          try {
541            caller.onRelease((str) => {
542                console.log(' Caller OnRelease CallBack is called ' + str);
543            });
544          } catch (error) {
545            console.log('Caller.onRelease catch error, error.code: ' + JSON.stringify(error.code) +
546              ' error.message: ' + JSON.stringify(error.message));
547          }
548      }).catch((err) => {
549        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
550          ' error.message: ' + JSON.stringify(err.message));
551      });
552    }
553  }
554  ```
555
556## Caller.on
557
558 on(type: 'release', callback: OnReleaseCallback): void;
559
560注册通用组件服务端Stub(桩)断开监听通知。
561
562**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
563
564**参数:**
565
566| 参数名 | 类型 | 必填 | 说明 |
567| -------- | -------- | -------- | -------- |
568| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
569| callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回onRelease回调结果。 |
570
571**错误码:**
572
573| 错误码ID | 错误信息 |
574| ------- | -------------------------------- |
575| 401 | If the input parameter is not valid parameter. |
576其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
577
578**示例:**
579
580  ```ts
581  let caller;
582  export default class MainAbility extends Ability {
583    onWindowStageCreate(windowStage) {
584      this.context.startAbilityByCall({
585        bundleName: 'com.example.myservice',
586        abilityName: 'MainAbility',
587        deviceId: ''
588      }).then((obj) => {
589          caller = obj;
590          try {
591            caller.on('release', (str) => {
592                console.log(' Caller OnRelease CallBack is called ' + str);
593            });
594          } catch (error) {
595            console.log('Caller.on catch error, error.code: ' + JSON.stringify(error.code) +
596              ' error.message: ' + JSON.stringify(error.message));
597          }
598      }).catch((err) => {
599        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
600          ' error.message: ' + JSON.stringify(err.message));
601      });
602    }
603  }
604  ```
605
606## Caller.off
607
608off(type: 'release', callback: OnReleaseCallback): void;
609
610取消注册通用组件服务端Stub(桩)断开监听通知。预留能力,当前暂未支持。
611
612**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
613
614**参数:**
615
616| 参数名 | 类型 | 必填 | 说明 |
617| -------- | -------- | -------- | -------- |
618| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
619| callback | [OnReleaseCallback](#onreleasecallback) | 是 | 返回off回调结果。 |
620
621**错误码:**
622
623| 错误码ID | 错误信息 |
624| ------- | -------------------------------- |
625| 401 | If the input parameter is not valid parameter. |
626其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
627
628**示例:**
629
630  ```ts
631  let caller;
632  export default class MainUIAbility extends Ability {
633    onWindowStageCreate(windowStage) {
634      this.context.startAbilityByCall({
635        bundleName: 'com.example.myservice',
636        abilityName: 'MainUIAbility',
637        deviceId: ''
638      }).then((obj) => {
639          caller = obj;
640          try {
641            let onReleaseCallBack = (str) => {
642                console.log(' Caller OnRelease CallBack is called ' + str);
643            };
644            caller.on('release', onReleaseCallBack);
645            caller.off('release', onReleaseCallBack);
646          } catch (error) {
647            console.log('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
648              ' error.message: ' + JSON.stringify(error.message));
649          }
650      }).catch((err) => {
651        console.log('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
652          ' error.message: ' + JSON.stringify(err.message));
653      });
654    }
655  }
656  ```
657
658## Caller.off
659
660off(type: 'release'): void;
661
662取消注册通用组件服务端Stub(桩)断开监听通知。预留能力,当前暂未支持。
663
664**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
665
666**参数:**
667
668| 参数名 | 类型 | 必填 | 说明 |
669| -------- | -------- | -------- | -------- |
670| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
671
672**错误码:**
673
674| 错误码ID | 错误信息 |
675| ------- | -------------------------------- |
676| 401 | If the input parameter is not valid parameter. |
677其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
678
679**示例:**
680
681  ```ts
682  let caller;
683  export default class MainUIAbility extends Ability {
684    onWindowStageCreate(windowStage) {
685      this.context.startAbilityByCall({
686        bundleName: 'com.example.myservice',
687        abilityName: 'MainUIAbility',
688        deviceId: ''
689      }).then((obj) => {
690          caller = obj;
691          try {
692            let onReleaseCallBack = (str) => {
693                console.log(' Caller OnRelease CallBack is called ' + str);
694            };
695            caller.on('release', onReleaseCallBack);
696            caller.off('release');
697          } catch (error) {
698            console.error('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
699              ' error.message: ' + JSON.stringify(error.message));
700          }
701      }).catch((err) => {
702        console.error('Caller GetCaller error, error.code: ' + JSON.stringify(err.code) +
703          ' error.message: ' + JSON.stringify(err.message));
704      });
705    }
706  }
707  ```
708
709## Callee
710
711通用组件服务端注册和解除客户端caller通知送信的callback接口。
712
713## Callee.on
714
715on(method: string, callback: CalleeCallback): void;
716
717通用组件服务端注册消息通知callback。
718
719**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
720
721**参数:**
722
723  | 参数名 | 类型 | 必填 | 说明 |
724  | -------- | -------- | -------- | -------- |
725  | method | string | 是 | 与客户端约定的通知消息字符串。 |
726  | callback | [CalleeCallback](#calleecallback) | 是 | 一个[rpc.MessageSequence](js-apis-rpc.md#messagesequence9)类型入参的js通知同步回调函数,&nbsp;回调函数至少要返回一个空的[rpc.Parcelable](js-apis-rpc.md#parcelable9)数据对象,&nbsp;其他视为函数执行错误。 |
727
728**错误码:**
729
730| 错误码ID | 错误信息 |
731| ------- | -------------------------------- |
732| 401 | If the input parameter is not valid parameter. |
733其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
734
735**示例:**
736
737  ```ts
738  class MyMessageAble{
739      name:''
740      str:''
741      num: 1
742      constructor(name, str) {
743        this.name = name;
744        this.str = str;
745      }
746      marshalling(messageSequence) {
747          messageSequence.writeInt(this.num);
748          messageSequence.writeString(this.str);
749          console.log('MyMessageAble marshalling num[' + this.num + '] str[' + this.str + ']');
750          return true;
751      }
752      unmarshalling(messageSequence) {
753          this.num = messageSequence.readInt();
754          this.str = messageSequence.readString();
755          console.log('MyMessageAble unmarshalling num[' + this.num + '] str[' + this.str + ']');
756          return true;
757      }
758  };
759  let method = 'call_Function';
760  function funcCallBack(pdata) {
761      console.log('Callee funcCallBack is called ' + pdata);
762      let msg = new MyMessageAble('test', '');
763      pdata.readParcelable(msg);
764      return new MyMessageAble('test1', 'Callee test');
765  }
766  export default class MainAbility extends Ability {
767    onCreate(want, launchParam) {
768      console.log('Callee onCreate is called');
769      try {
770        this.callee.on(method, funcCallBack);
771      } catch (error) {
772        console.log('Callee.on catch error, error.code: ' + JSON.stringify(error.code) +
773          ' error.message: ' + JSON.stringify(error.message));
774      }
775    }
776  }
777  ```
778
779## Callee.off
780
781off(method: string): void;
782
783解除通用组件服务端注册消息通知callback。
784
785**系统能力**:SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore
786
787**参数:**
788
789| 参数名 | 类型 | 必填 | 说明 |
790| -------- | -------- | -------- | -------- |
791| method | string | 是 | 已注册的通知事件字符串。 |
792
793**错误码:**
794
795| 错误码ID | 错误信息 |
796| ------- | -------------------------------- |
797| 401 | If the input parameter is not valid parameter. |
798其他ID见[元能力子系统错误码](../errorcodes/errorcode-ability.md)
799
800
801**示例:**
802
803  ```ts
804  let method = 'call_Function';
805  export default class MainAbility extends Ability {
806    onCreate(want, launchParam) {
807      console.log('Callee onCreate is called');
808      try {
809        this.callee.off(method);
810      } catch (error) {
811        console.log('Callee.off catch error, error.code: ' + JSON.stringify(error.code) +
812          ' error.message: ' + JSON.stringify(error.message));
813      }
814    }
815  }
816  ```
817
818## OnReleaseCallback
819
820(msg: string): void;
821
822**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
823
824| 名称 | 可读 | 可写 | 类型 | 说明 |
825| -------- | -------- | -------- | -------- | -------- |
826| (msg: string) | 是 | 否 | function | 调用者注册的侦听器函数接口的原型。 |
827
828## CalleeCallback
829
830(indata: rpc.MessageSequence): rpc.Parcelable;
831
832**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore
833
834| 名称 | 可读 | 可写 | 类型 | 说明 |
835| -------- | -------- | -------- | -------- | -------- |
836| (indata: [rpc.MessageSequence](js-apis-rpc.md#messagesequence9)) | 是 | 否 | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | 被调用方注册的消息侦听器函数接口的原型。 |
837