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: string]: 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<void>; 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<void> | Promise used to return a response.| 329 330**Error codes** 331 332| ID| Error Message| 333| ------- | -------------------------------- | 334| 401 | If the input parameter is not valid parameter. | 335For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 336 337**Example** 338 339 ```ts 340 class MyMessageAble{ // Custom parcelable data structure. 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'; // Notification message string negotiated by the two abilities. 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'); // See the definition of 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<rpc.MessageSequence>; 392 393Sends parcelable data to the target ability and obtains the parcelable data returned by the target ability. 394 395**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 396 397**Parameters** 398 399 | Name| Type| Mandatory| Description| 400 | -------- | -------- | -------- | -------- | 401 | 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.| 402 | data | [rpc.Parcelable](js-apis-rpc.md#parcelable9) | Yes| Parcelable data. You need to customize the data.| 403 404**Return value** 405 406 | Type| Description| 407 | -------- | -------- | 408 | Promise<[rpc.MessageSequence](js-apis-rpc.md#messagesequence9)> | Promise used to return the parcelable data from the target ability.| 409 410**Error codes** 411 412| ID| Error Message| 413| ------- | -------------------------------- | 414| 401 | If the input parameter is not valid parameter. | 415For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 416 417**Example** 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 475Releases the caller interface of the target ability. 476 477**System capability**: SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore 478 479**Error codes** 480 481| ID| Error Message| 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**Example** 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 518Registers a callback that is invoked when the stub on the target ability is disconnected. 519 520**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 521 522**Parameters** 523 524| Name| Type| Mandatory| Description| 525| -------- | -------- | -------- | -------- | 526| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.| 527 528**Example** 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 560Registers a callback that is invoked when the stub on the target ability is disconnected. 561 562**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 563 564**Parameters** 565 566| Name| Type| Mandatory| Description| 567| -------- | -------- | -------- | -------- | 568| type | string | Yes| Event type. The value is fixed at **release**.| 569| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.| 570 571**Error codes** 572 573| ID| Error Message| 574| ------- | -------------------------------- | 575| 401 | If the input parameter is not valid parameter. | 576For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 577 578**Example** 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 610Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved. 611 612**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 613 614**Parameters** 615 616| Name| Type| Mandatory| Description| 617| -------- | -------- | -------- | -------- | 618| type | string | Yes| Event type. The value is fixed at **release**.| 619| callback | [OnReleaseCallback](#onreleasecallback) | Yes| Callback used to return the result.| 620 621**Error codes** 622 623| ID| Error Message| 624| ------- | -------------------------------- | 625| 401 | If the input parameter is not valid parameter. | 626For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 627 628**Example** 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 662Deregisters a callback that is invoked when the stub on the target ability is disconnected. This capability is reserved. 663 664**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 665 666**Parameters** 667 668| Name| Type| Mandatory| Description| 669| -------- | -------- | -------- | -------- | 670| type | string | Yes| Event type. The value is fixed at **release**.| 671 672**Error codes** 673 674| ID| Error Message| 675| ------- | -------------------------------- | 676| 401 | If the input parameter is not valid parameter. | 677For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 678 679**Example** 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 711Implements callbacks for caller notification registration and deregistration. 712 713## Callee.on 714 715on(method: string, callback: CalleeCallback): void; 716 717Registers a caller notification callback, which is invoked when the target ability registers a function. 718 719**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 720 721**Parameters** 722 723 | Name| Type| Mandatory| Description| 724 | -------- | -------- | -------- | -------- | 725 | method | string | Yes| Notification message string negotiated between the two abilities.| 726 | 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.| 727 728**Error codes** 729 730| ID| Error Message| 731| ------- | -------------------------------- | 732| 401 | If the input parameter is not valid parameter. | 733For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 734 735**Example** 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 783Deregisters a caller notification callback, which is invoked when the target ability registers a function. 784 785**System capability**: SystemCapability.UIAbility.UIAbilityRuntime.UIAbilityCore 786 787**Parameters** 788 789| Name| Type| Mandatory| Description| 790| -------- | -------- | -------- | -------- | 791| method | string | Yes| Registered notification message string.| 792 793**Error codes** 794 795| ID| Error Message| 796| ------- | -------------------------------- | 797| 401 | If the input parameter is not valid parameter. | 798For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 799 800 801**Example** 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**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 823 824| Name| Readable| Writable| Type| Description| 825| -------- | -------- | -------- | -------- | -------- | 826| (msg: string) | Yes| No| function | Prototype of the listener function registered by the caller.| 827 828## CalleeCallback 829 830(indata: rpc.MessageSequence): rpc.Parcelable; 831 832**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore 833 834| Name| Readable| Writable| Type| Description| 835| -------- | -------- | -------- | -------- | -------- | 836| (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.| 837