1# @ohos.application.missionManager (missionManager) 2 3The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.missionManager](js-apis-app-ability-missionManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import missionManager from '@ohos.application.missionManager'; 13``` 14 15## Required Permissions 16 17ohos.permission.MANAGE_MISSIONS 18 19## missionManager.registerMissionListener 20 21registerMissionListener(listener: MissionListener): number 22 23Registers a listener to observe the mission status. 24 25**Required permissions**: ohos.permission.MANAGE_MISSIONS 26 27**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 28 29**System API**: This is a system API. 30 31**Parameters** 32 33 | Name| Type| Mandatory| Description| 34 | -------- | -------- | -------- | -------- | 35 | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.| 36 37**Return value** 38 39 | Type| Description| 40 | -------- | -------- | 41 | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.| 42 43**Example** 44 45```ts 46import missionManager from '@ohos.application.missionManager'; 47 48console.log('registerMissionListener'); 49let listenerid = missionManager.registerMissionListener({ 50 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 51 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 52 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 53 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 54 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 55 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 56 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 57}); 58``` 59 60 61## missionManager.unregisterMissionListener 62 63unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>): void 64 65Deregisters a mission status listener. This API uses an asynchronous callback to return the result. 66 67**Required permissions**: ohos.permission.MANAGE_MISSIONS 68 69**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 70 71**System API**: This is a system API. 72 73**Parameters** 74 75 | Name| Type| Mandatory| Description| 76 | -------- | -------- | -------- | -------- | 77 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.| 78 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 79 80**Example** 81 82```ts 83 import missionManager from '@ohos.application.missionManager'; 84 85 console.log('registerMissionListener'); 86 let listenerid = missionManager.registerMissionListener({ 87 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 88 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 89 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 90 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 91 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 92 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 93 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 94 }); 95 96 missionManager.unregisterMissionListener(listenerid, (error) => { 97 console.error('unregisterMissionListener fail, error: ${error}'); 98 }); 99``` 100 101 102## missionManager.unregisterMissionListener 103 104unregisterMissionListener(listenerId: number): Promise<void> 105 106Unregisters a mission status listener. This API uses a promise to return the result. 107 108**Required permissions**: ohos.permission.MANAGE_MISSIONS 109 110**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 111 112**System API**: This is a system API. 113 114**Parameters** 115 116 | Name| Type| Mandatory| Description| 117 | -------- | -------- | -------- | -------- | 118 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.| 119 120**Return value** 121 122 | Type| Description| 123 | -------- | -------- | 124 | Promise<void> | Promise that returns no value.| 125 126**Example** 127 128```ts 129 import missionManager from '@ohos.application.missionManager'; 130 import { BusinessError } from '@ohos.base'; 131 132 console.log('registerMissionListener'); 133 let listenerid = missionManager.registerMissionListener({ 134 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 135 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 136 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 137 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 138 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 139 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 140 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 141 }); 142 143 missionManager.unregisterMissionListener(listenerid).catch((error: BusinessError) => { 144 console.error('unregisterMissionListener fail, error: ${error}'); 145 }); 146``` 147 148 149## missionManager.getMissionInfo 150 151getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void 152 153Obtains the information about a given mission. This API uses an asynchronous callback to return the result. 154 155**Required permissions**: ohos.permission.MANAGE_MISSIONS 156 157**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 158 159**System API**: This is a system API. 160 161**Parameters** 162 163 | Name| Type| Mandatory| Description| 164 | -------- | -------- | -------- | -------- | 165 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 166 | missionId | number | Yes| Mission ID.| 167 | callback | AsyncCallback<[MissionInfo](js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.| 168 169**Example** 170 171 ```ts 172 import missionManager from '@ohos.application.missionManager'; 173 import { BusinessError } from '@ohos.base'; 174 175 let allMissions=missionManager.getMissionInfos('',10).catch((err: BusinessError) => { 176 console.log(`${err}`);}); 177 missionManager.getMissionInfo('', allMissions[0].missionId, (error, mission) => { 178 if (error.code) { 179 console.error(`getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}`); 180 return; 181 } 182 183 console.log(`mission.missionId = ${mission.missionId}`); 184 console.log(`mission.runningState = ${mission.runningState}`); 185 console.log(`mission.lockedState = ${mission.lockedState}`); 186 console.log(`mission.timestamp = ${mission.timestamp}`); 187 console.log(`mission.label = ${mission.label}`); 188 console.log(`mission.iconPath = ${mission.iconPath}`); 189 }); 190 ``` 191 192 193## missionManager.getMissionInfo 194 195getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo> 196 197Obtains the information about a given mission. This API uses a promise to return the result. 198 199**Required permissions**: ohos.permission.MANAGE_MISSIONS 200 201**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 202 203**System API**: This is a system API. 204 205**Parameters** 206 207 | Name| Type| Mandatory| Description| 208 | -------- | -------- | -------- | -------- | 209 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 210 | missionId | number | Yes| Mission ID.| 211 212**Return value** 213 214 | Type| Description| 215 | -------- | -------- | 216 | Promise<[MissionInfo](js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.| 217 218**Example** 219 220 ```ts 221 import missionManager from '@ohos.application.missionManager'; 222 import { BusinessError } from '@ohos.base'; 223 224 let testMissionId = 1; 225try { 226 missionManager.getMissionInfo('', testMissionId).then((data) => { 227 console.info(`getMissionInfo successfully. Data: ${JSON.stringify(data)}`); 228 }).catch((error: BusinessError) => { 229 console.error(`getMissionInfo failed. Cause: ${error.message}`); 230 }); 231} catch (error) { 232 console.error(`getMissionInfo failed. Cause: ${error.message}`); 233} 234 ``` 235 236 237## missionManager.getMissionInfos 238 239getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void 240 241Obtains information about all missions. This API uses an asynchronous callback to return the result. 242 243**Required permissions**: ohos.permission.MANAGE_MISSIONS 244 245**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 246 247**System API**: This is a system API. 248 249**Parameters** 250 251 | Name| Type| Mandatory| Description| 252 | -------- | -------- | -------- | -------- | 253 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 254 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 255 | callback | AsyncCallback<Array<[MissionInfo](js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.| 256 257**Example** 258 259 ```ts 260 import missionManager from '@ohos.application.missionManager'; 261 262 missionManager.getMissionInfos('', 10, (error, missions) => { 263 if (error.code) { 264 console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`); 265 return; 266 } 267 console.log(`size = ${missions.length}`); 268 console.log(`missions = ${JSON.stringify(missions)}`); 269 }); 270 ``` 271 272 273## missionManager.getMissionInfos 274 275getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>> 276 277Obtains information about all missions. This API uses a promise to return the result. 278 279**Required permissions**: ohos.permission.MANAGE_MISSIONS 280 281**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 282 283**System API**: This is a system API. 284 285**Parameters** 286 287 | Name| Type| Mandatory| Description| 288 | -------- | -------- | -------- | -------- | 289 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 290 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 291 292**Return value** 293 294 | Type| Description| 295 | -------- | -------- | 296 | Promise<Array<[MissionInfo](js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.| 297 298**Example** 299 300 ```ts 301 import missionManager from '@ohos.application.missionManager'; 302 import { BusinessError } from '@ohos.base'; 303 304 try { 305 missionManager.getMissionInfos('', 10).then((data) => { 306 console.info(`getMissionInfos successfully. Data: ${JSON.stringify(data)}`); 307 }).catch((error: BusinessError) => { 308 console.error(`getMissionInfos failed. Cause: ${error.message}`); 309 }); 310} catch (error) { 311 console.error(`getMissionInfos failed. Cause: ${error.message}`); 312} 313 ``` 314 315 316## missionManager.getMissionSnapShot 317 318getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void 319 320Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result. 321 322**Required permissions**: ohos.permission.MANAGE_MISSIONS 323 324**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 325 326**System API**: This is a system API. 327 328**Parameters** 329 330 | Name| Type| Mandatory| Description| 331 | -------- | -------- | -------- | -------- | 332 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 333 | missionId | number | Yes| Mission ID.| 334 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 335 336**Example** 337 338 ```ts 339 import missionManager from '@ohos.application.missionManager'; 340 341 let testMissionId = 2; 342try { 343 missionManager.getMissionSnapShot('', testMissionId, (err, data) => { 344 if (err) { 345 console.error(`getMissionSnapShot failed: ${err.message}`); 346 } else { 347 console.info(`getMissionSnapShot successfully: ${JSON.stringify(data)}`); 348 } 349 }); 350} catch (err) { 351 console.error(`getMissionSnapShot failed: ${err.message}`); 352} 353 ``` 354 355 356## missionManager.getMissionSnapShot 357 358getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot> 359 360Obtains the snapshot of a given mission. This API uses a promise to return the result. 361 362**Required permissions**: ohos.permission.MANAGE_MISSIONS 363 364**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 365 366**System API**: This is a system API. 367 368**Parameters** 369 370 | Name| Type| Mandatory| Description| 371 | -------- | -------- | -------- | -------- | 372 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 373 | missionId | number | Yes| Mission ID.| 374 375**Return value** 376 377 | Type| Description| 378 | -------- | -------- | 379 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 380 381**Example** 382 383 ```ts 384 import missionManager from '@ohos.application.missionManager'; 385 import { BusinessError } from '@ohos.base'; 386 387 let testMissionId = 2; 388try { 389 missionManager.getMissionSnapShot('', testMissionId).then((data) => { 390 console.info(`getMissionSnapShot successfully. Data: ${JSON.stringify(data)}`); 391 }).catch((error: BusinessError) => { 392 console.error(`getMissionSnapShot failed. Cause: ${error.message}`); 393 }); 394} catch (error) { 395 console.error(`getMissionSnapShot failed. Cause: ${error.message}`); 396} 397 ``` 398 399## missionManager.lockMission 400 401lockMission(missionId: number, callback: AsyncCallback<void>): void 402 403Locks a given mission. This API uses an asynchronous callback to return the result. 404 405**Required permissions**: ohos.permission.MANAGE_MISSIONS 406 407**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 408 409**System API**: This is a system API. 410 411**Parameters** 412 413 | Name| Type| Mandatory| Description| 414 | -------- | -------- | -------- | -------- | 415 | missionId | number | Yes| Mission ID.| 416 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the mission is locked, **err** is **undefined**. Otherwise, **err** is an error object.| 417 418**Example** 419 420 ```ts 421 import missionManager from '@ohos.application.missionManager'; 422 423 let testMissionId = 2; 424try { 425 missionManager.lockMission(testMissionId, (err, data) => { 426 if (err) { 427 console.error(`lockMission failed: ${err.message}`); 428 } else { 429 console.info(`lockMission successfully: ${JSON.stringify(data)}`); 430 } 431 }); 432} catch (err) { 433 console.error(`lockMission failed: ${err.message}`); 434} 435 ``` 436 437 438## missionManager.lockMission 439 440lockMission(missionId: number): Promise<void> 441 442Locks a given mission. This API uses a promise to return the result. 443 444**Required permissions**: ohos.permission.MANAGE_MISSIONS 445 446**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 447 448**System API**: This is a system API. 449 450**Parameters** 451 452 | Name| Type| Mandatory| Description| 453 | -------- | -------- | -------- | -------- | 454 | missionId | number | Yes| Mission ID.| 455 456**Return value** 457 458 | Type| Description| 459 | -------- | -------- | 460 | Promise<void> | Promise that returns no value.| 461 462**Example** 463 464 ```ts 465 import missionManager from '@ohos.application.missionManager'; 466 import { BusinessError } from '@ohos.base'; 467 468 let testMissionId = 2; 469try { 470 missionManager.lockMission(testMissionId).then((data) => { 471 console.info(`lockMission successfully. Data: ${JSON.stringify(data)}`); 472 }).catch((error: BusinessError) => { 473 console.error(`lockMission failed. Cause: ${error.message}`); 474 }); 475} catch (error) { 476 console.error(`lockMission failed. Cause: ${error.message}`); 477} 478 ``` 479 480 481## missionManager.unlockMission 482 483unlockMission(missionId: number, callback: AsyncCallback<void>): void 484 485Unlocks a given mission. This API uses an asynchronous callback to return the result. 486 487**Required permissions**: ohos.permission.MANAGE_MISSIONS 488 489**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 490 491**System API**: This is a system API. 492 493**Parameters** 494 495| Name| Type| Mandatory| Description| 496| -------- | -------- | -------- | -------- | 497| missionId | number | Yes| Mission ID.| 498| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the mission is unlocked, **err** is **undefined**. Otherwise, **err** is an error object.| 499 500**Example** 501 502 ```ts 503 import missionManager from '@ohos.application.missionManager'; 504 505 let testMissionId = 2; 506try { 507 missionManager.unlockMission(testMissionId, (err, data) => { 508 if (err) { 509 console.error(`unlockMission failed: ${err.message}`); 510 } else { 511 console.info(`unlockMission successfully: ${JSON.stringify(data)}`); 512 } 513 }); 514} catch (err) { 515 console.error(`unlockMission failed: ${err.message}`); 516} 517 ``` 518 519 520## missionManager.unlockMission 521 522unlockMission(missionId: number): Promise<void> 523 524Unlocks a given mission. This API uses a promise to return the result. 525 526**Required permissions**: ohos.permission.MANAGE_MISSIONS 527 528**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 529 530**System API**: This is a system API. 531 532**Parameters** 533 534 | Name| Type| Mandatory| Description| 535 | -------- | -------- | -------- | -------- | 536 | missionId | number | Yes| Mission ID.| 537 538**Return value** 539 540 | Type| Description| 541 | -------- | -------- | 542 | Promise<void> | Promise that returns no value.| 543 544**Example** 545 546 ```ts 547 import missionManager from '@ohos.application.missionManager'; 548 import { BusinessError } from '@ohos.base'; 549 550 let testMissionId = 2; 551try { 552 missionManager.unlockMission(testMissionId).then((data) => { 553 console.info(`unlockMission successfully. Data: ${JSON.stringify(data)}`); 554 }).catch((error: BusinessError) => { 555 console.error(`unlockMission failed. Cause: ${error.message}`); 556 }); 557} catch (error) { 558 console.error(`unlockMission failed. Cause: ${error.message}`); 559} 560 ``` 561 562 563## missionManager.clearMission 564 565clearMission(missionId: number, callback: AsyncCallback<void>): void 566 567Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result. 568 569**Required permissions**: ohos.permission.MANAGE_MISSIONS 570 571**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 572 573**System API**: This is a system API. 574 575**Parameters** 576 577 | Name| Type| Mandatory| Description| 578 | -------- | -------- | -------- | -------- | 579 | missionId | number | Yes| Mission ID.| 580 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the mission is cleared, **err** is **undefined**. Otherwise, **err** is an error object.| 581 582**Example** 583 584 ```ts 585 import missionManager from '@ohos.application.missionManager'; 586 587 let testMissionId = 2; 588try { 589 missionManager.clearMission(testMissionId, (err, data) => { 590 if (err) { 591 console.error(`clearMission failed: ${err.message}`); 592 } else { 593 console.info(`clearMission successfully: ${JSON.stringify(data)}`); 594 } 595 }); 596} catch (err) { 597 console.error(`clearMission failed: ${err.message}`); 598} 599 ``` 600 601 602## missionManager.clearMission 603 604clearMission(missionId: number): Promise<void> 605 606Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result. 607 608**Required permissions**: ohos.permission.MANAGE_MISSIONS 609 610**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 611 612**System API**: This is a system API. 613 614**Parameters** 615 616 | Name| Type| Mandatory| Description| 617 | -------- | -------- | -------- | -------- | 618 | missionId | number | Yes| Mission ID.| 619 620**Return value** 621 622 | Type| Description| 623 | -------- | -------- | 624 | Promise<void> | Promise that returns no value.| 625 626**Example** 627 628 ```ts 629 import missionManager from '@ohos.application.missionManager'; 630 import { BusinessError } from '@ohos.base'; 631 632 let testMissionId = 2; 633try { 634 missionManager.clearMission(testMissionId).then((data) => { 635 console.info(`clearMission successfully. Data: ${JSON.stringify(data)}`); 636 }).catch((error: BusinessError) => { 637 console.error(`clearMission failed. Cause: ${error.message}`); 638 }); 639} catch (error) { 640 console.error(`clearMission failed. Cause: ${error.message}`); 641} 642 ``` 643 644 645## missionManager.clearAllMissions 646 647clearAllMissions(callback: AsyncCallback<void>): void 648 649Clears all unlocked missions. This API uses an asynchronous callback to return the result. 650 651**Required permissions**: ohos.permission.MANAGE_MISSIONS 652 653**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 654 655**System API**: This is a system API. 656 657**Parameters** 658 659 | Name| Type| Mandatory| Description| 660 | -------- | -------- | -------- | -------- | 661 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If all the unlocked missions are cleared, **err** is **undefined**. Otherwise, **err** is an error object.| 662 663**Example** 664 665 ```ts 666 import missionManager from '@ohos.application.missionManager' 667 668 try { 669 missionManager.clearAllMissions(err => { 670 if (err) { 671 console.error('clearAllMissions failed: ${err.message}'); 672 } else { 673 console.info('clearAllMissions successfully.'); 674 } 675 }); 676} catch (err) { 677 console.error('clearAllMissions failed: ${err.message}'); 678} 679 ``` 680 681 682## missionManager.clearAllMissions 683 684clearAllMissions(): Promise<void> 685 686Clears all unlocked missions. This API uses a promise to return the result. 687 688**Required permissions**: ohos.permission.MANAGE_MISSIONS 689 690**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 691 692**System API**: This is a system API. 693 694**Return value** 695 696 | Type| Description| 697 | -------- | -------- | 698 | Promise<void> | Promise that returns no value.| 699 700**Example** 701 702 ```ts 703 import missionManager from '@ohos.application.missionManager'; 704 import { BusinessError } from '@ohos.base'; 705 706 try { 707 missionManager.clearAllMissions().then((data) => { 708 console.info(`clearAllMissions successfully. Data: ${JSON.stringify(data)}`); 709 }).catch((err: BusinessError) => { 710 console.error(`clearAllMissions failed: ${err.message}`); 711 }); 712} catch (err) { 713 console.error(`clearAllMissions failed: ${err.message}`); 714} 715 ``` 716 717 718## missionManager.moveMissionToFront 719 720moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void 721 722Switches a given mission to the foreground. This API uses an asynchronous callback to return the result. 723 724**Required permissions**: ohos.permission.MANAGE_MISSIONS 725 726**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 727 728**System API**: This is a system API. 729 730**Parameters** 731 732 | Name| Type| Mandatory| Description| 733 | -------- | -------- | -------- | -------- | 734 | missionId | number | Yes| Mission ID.| 735 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the mission is switched to the foreground, **err** is **undefined**. Otherwise, **err** is an error object.| 736 737**Example** 738 739 ```ts 740 import missionManager from '@ohos.application.missionManager'; 741 742 let testMissionId = 2; 743try { 744 missionManager.moveMissionToFront(testMissionId, (err, data) => { 745 if (err) { 746 console.error(`moveMissionToFront failed: ${err.message}`); 747 } else { 748 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 749 } 750 }); 751} catch (err) { 752 console.error(`moveMissionToFront failed: ${err.message}`); 753} 754 ``` 755 756 757## missionManager.moveMissionToFront 758 759moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void 760 761Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result. 762 763**Required permissions**: ohos.permission.MANAGE_MISSIONS 764 765**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 766 767**System API**: This is a system API. 768 769**Parameters** 770 771 | Name| Type| Mandatory| Description| 772 | -------- | -------- | -------- | -------- | 773 | missionId | number | Yes| Mission ID.| 774 | options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| 775 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the mission is switched to the foreground, **err** is **undefined**. Otherwise, **err** is an error object.| 776 777**Example** 778 779 ```ts 780 import missionManager from '@ohos.application.missionManager'; 781 782 let testMissionId = 2; 783try { 784 missionManager.moveMissionToFront(testMissionId, {windowMode : 101}, (err, data) => { 785 if (err) { 786 console.error(`moveMissionToFront failed: ${err.message}`); 787 } else { 788 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 789 } 790 }); 791} catch (err) { 792 console.error(`moveMissionToFront failed: ${err.message}`); 793} 794 ``` 795 796 797## missionManager.moveMissionToFront 798 799moveMissionToFront(missionId: number, options?: StartOptions): Promise<void> 800 801Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result. 802 803**Required permissions**: ohos.permission.MANAGE_MISSIONS 804 805**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 806 807**System API**: This is a system API. 808 809**Parameters** 810 811 | Name| Type| Mandatory| Description| 812 | -------- | -------- | -------- | -------- | 813 | missionId | number | Yes| Mission ID.| 814 | options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| 815 816**Return value** 817 818 | Type| Description| 819 | -------- | -------- | 820 | Promise<void> | Promise that returns no value.| 821 822**Example** 823 824 ```ts 825 import missionManager from '@ohos.application.missionManager'; 826 import { BusinessError } from '@ohos.base'; 827 828 let testMissionId = 2; 829try { 830 missionManager.moveMissionToFront(testMissionId).then((data) => { 831 console.info(`moveMissionToFront successfully. Data: ${JSON.stringify(data)}`); 832 }).catch((error: BusinessError) => { 833 console.error(`moveMissionToFront failed. Cause: ${error.message}`); 834 }); 835} catch (error) { 836 console.error(`moveMissionToFront failed. Cause: ${error.message}`); 837} 838 ``` 839