1# @ohos.app.ability.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 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. 8 9## Modules to Import 10 11```ts 12import missionManager from '@ohos.app.ability.missionManager'; 13``` 14 15## Required Permissions 16 17ohos.permission.MANAGE_MISSIONS 18 19## missionManager.on 20 21on(type:'mission', 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 and cannot be called by third-party applications. 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.app.ability.missionManager'; 47import UIAbility from '@ohos.app.ability.UIAbility'; 48import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 49import common from '@ohos.app.ability.common'; 50import Want from '@ohos.app.ability.Want'; 51import { BusinessError } from '@ohos.base'; 52import window from '@ohos.window'; 53 54let listener: missionManager.MissionListener = { 55 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 56 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 57 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 58 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 59 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 60 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 61 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 62}; 63 64let listenerId = -1; 65let abilityWant: Want; 66let context: common.UIAbilityContext; 67 68export default class EntryAbility extends UIAbility { 69 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 70 console.log('[Demo] EntryAbility onCreate'); 71 abilityWant = want; 72 context = this.context; 73 } 74 75 onDestroy() { 76 try { 77 if (listenerId !== -1) { 78 missionManager.off('mission', listenerId).catch((err: BusinessError) => { 79 console.log(err); 80 }); 81 } 82 } catch (paramError) { 83 let code = (paramError as BusinessError).code; 84 let message = (paramError as BusinessError).message; 85 console.error(`error: ${code}, ${message} `); 86 } 87 console.log('[Demo] EntryAbility onDestroy'); 88 } 89 90 onWindowStageCreate(windowStage: window.WindowStage) { 91 // The main window is created. Set a main page for this ability. 92 console.log('[Demo] EntryAbility onWindowStageCreate'); 93 try { 94 listenerId = missionManager.on('mission', listener); 95 } catch (paramError) { 96 let code = (paramError as BusinessError).code; 97 let message = (paramError as BusinessError).message; 98 console.error(`error: ${code}, ${message} `); 99 } 100 101 windowStage.loadContent('pages/index', (err, data) => { 102 if (err.code) { 103 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 104 return; 105 } 106 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 107 }); 108 } 109}; 110``` 111 112 113## missionManager.off 114 115off(type: 'mission', listenerId: number, callback: AsyncCallback<void>): void; 116 117Deregisters a mission status listener. 118 119**Required permissions**: ohos.permission.MANAGE_MISSIONS 120 121**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 122 123**System API**: This is a system API and cannot be called by third-party applications. 124 125**Parameters** 126 127 | Name| Type| Mandatory| Description| 128 | -------- | -------- | -------- | -------- | 129 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.| 130 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 131 132**Error codes** 133 134| ID| Error Message| 135| ------- | -------- | 136| 16300002 | Input error. The specified mission listener does not exist. | 137 138For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 139 140**Example** 141 142```ts 143import missionManager from '@ohos.app.ability.missionManager'; 144import UIAbility from '@ohos.app.ability.UIAbility'; 145import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 146import common from '@ohos.app.ability.common'; 147import Want from '@ohos.app.ability.Want'; 148import { BusinessError } from '@ohos.base'; 149import window from '@ohos.window'; 150 151let listener: missionManager.MissionListener = { 152 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 153 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 154 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 155 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 156 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 157 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 158 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 159}; 160 161let listenerId = -1; 162let abilityWant: Want; 163let context: common.UIAbilityContext; 164 165export default class EntryAbility extends UIAbility { 166 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 167 console.log('[Demo] EntryAbility onCreate'); 168 abilityWant = want; 169 context = this.context; 170 } 171 172 onDestroy() { 173 try { 174 if (listenerId !== -1) { 175 missionManager.off('mission', listenerId, (err) => { 176 console.log('$(err.code)'); 177 }); 178 } 179 } catch (paramError) { 180 let code = (paramError as BusinessError).code; 181 let message = (paramError as BusinessError).message; 182 console.error(`error: ${code}, ${message} `); 183 } 184 console.log('[Demo] EntryAbility onDestroy'); 185 } 186 187 onWindowStageCreate(windowStage: window.WindowStage) { 188 // The main window is created. Set a main page for this ability. 189 console.log('[Demo] EntryAbility onWindowStageCreate'); 190 try { 191 listenerId = missionManager.on('mission', listener); 192 } catch (paramError) { 193 let code = (paramError as BusinessError).code; 194 let message = (paramError as BusinessError).message; 195 console.error(`error: ${code}, ${message} `); 196 } 197 198 windowStage.loadContent('pages/index', (err: BusinessError, data) => { 199 if (err.code) { 200 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 201 return; 202 } 203 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 204 }); 205 } 206}; 207``` 208 209 210## missionManager.off 211 212off(type: 'mission', listenerId: number): Promise<void>; 213 214Deregisters a mission status listener. This API uses a promise to return the result. 215 216**Required permissions**: ohos.permission.MANAGE_MISSIONS 217 218**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 219 220**System API**: This is a system API and cannot be called by third-party applications. 221 222**Parameters** 223 224 | Name| Type| Mandatory| Description| 225 | -------- | -------- | -------- | -------- | 226 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.| 227 228**Return value** 229 230 | Type| Description| 231 | -------- | -------- | 232 | Promise<void> | Promise used to return the result.| 233 234**Error codes** 235 236| ID| Error Message| 237| ------- | -------- | 238| 16300002 | Input error. The specified mission listener does not exist. | 239 240For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 241 242**Example** 243 244```ts 245import missionManager from '@ohos.app.ability.missionManager'; 246import UIAbility from '@ohos.app.ability.UIAbility'; 247import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 248import common from '@ohos.app.ability.common'; 249import Want from '@ohos.app.ability.Want'; 250import { BusinessError } from '@ohos.base'; 251import window from '@ohos.window'; 252 253let listener: missionManager.MissionListener = { 254 onMissionCreated: (mission) => {console.log('--------onMissionCreated-------');}, 255 onMissionDestroyed: (mission) => {console.log('--------onMissionDestroyed-------');}, 256 onMissionSnapshotChanged: (mission) => {console.log('--------onMissionSnapshotChanged-------');}, 257 onMissionMovedToFront: (mission) => {console.log('--------onMissionMovedToFront-------');}, 258 onMissionIconUpdated: (mission, icon) => {console.log('--------onMissionIconUpdated-------');}, 259 onMissionClosed: (mission) => {console.log('--------onMissionClosed-------');}, 260 onMissionLabelUpdated: (mission) => {console.log('--------onMissionLabelUpdated-------');} 261}; 262 263let listenerId = -1; 264let abilityWant: Want; 265let context: common.UIAbilityContext; 266 267export default class EntryAbility extends UIAbility { 268 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 269 console.log('[Demo] EntryAbility onCreate'); 270 abilityWant = want; 271 context = this.context; 272 } 273 274 onDestroy() { 275 try { 276 if (listenerId !== -1) { 277 missionManager.off('mission', listenerId).catch((err: BusinessError) => { 278 console.log('$(err.code)'); 279 }); 280 } 281 } catch (paramError) { 282 let code = (paramError as BusinessError).code; 283 let message = (paramError as BusinessError).message; 284 console.error(`error: ${code}, ${message} `); 285 } 286 console.log('[Demo] EntryAbility onDestroy'); 287 } 288 289 onWindowStageCreate(windowStage: window.WindowStage) { 290 // The main window is created. Set a main page for this ability. 291 console.log('[Demo] EntryAbility onWindowStageCreate'); 292 try { 293 listenerId = missionManager.on('mission', listener); 294 } catch (paramError) { 295 let code = (paramError as BusinessError).code; 296 let message = (paramError as BusinessError).message; 297 console.error(`error: ${code}, ${message} `); 298 } 299 300 windowStage.loadContent('pages/index', (err: BusinessError, data) => { 301 if (err.code) { 302 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 303 return; 304 } 305 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 306 }); 307 } 308}; 309``` 310 311 312## missionManager.getMissionInfo 313 314getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void; 315 316Obtains the information about a given mission. This API uses an asynchronous callback to return the result. 317 318**Required permissions**: ohos.permission.MANAGE_MISSIONS 319 320**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 321 322**System API**: This is a system API and cannot be called by third-party applications. 323 324**Parameters** 325 326 | Name| Type| Mandatory| Description| 327 | -------- | -------- | -------- | -------- | 328 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 329 | missionId | number | Yes| Mission ID.| 330 | callback | AsyncCallback<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.| 331 332**Example** 333 334 ```ts 335 import missionManager from '@ohos.app.ability.missionManager'; 336 import { BusinessError } from '@ohos.base'; 337 338 let testMissionId = 1; 339 340 missionManager.getMissionInfos('',10) 341 .then((allMissions) => { 342 try { 343 if (allMissions && allMissions.length > 0) { 344 testMissionId = allMissions[0].missionId; 345 } 346 347 missionManager.getMissionInfo('', testMissionId, (error, mission) => { 348 if (error) { 349 console.error('getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}'); 350 } else { 351 console.log('mission.missionId = ${mission.missionId}'); 352 console.log('mission.runningState = ${mission.runningState}'); 353 console.log('mission.lockedState = ${mission.lockedState}'); 354 console.log('mission.timestamp = ${mission.timestamp}'); 355 console.log('mission.label = ${mission.label}'); 356 console.log('mission.iconPath = ${mission.iconPath}'); 357 } 358 }); 359 } catch (paramError) { 360 let code = (paramError as BusinessError).code; 361 let message = (paramError as BusinessError).message; 362 console.error(`error: ${code}, ${message} `); 363 } 364 }) 365 .catch((err: BusinessError) => {console.log('$(err.code)');}); 366 ``` 367 368## missionManager.getMissionInfo 369 370getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>; 371 372Obtains the information about a given mission. This API uses a promise to return the result. 373 374**Required permissions**: ohos.permission.MANAGE_MISSIONS 375 376**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 377 378**System API**: This is a system API and cannot be called by third-party applications. 379 380**Parameters** 381 382 | Name| Type| Mandatory| Description| 383 | -------- | -------- | -------- | -------- | 384 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 385 | missionId | number | Yes| Mission ID.| 386 387**Return value** 388 389 | Type| Description| 390 | -------- | -------- | 391 | Promise<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.| 392 393**Example** 394 395```ts 396import missionManager from '@ohos.app.ability.missionManager'; 397import { BusinessError } from '@ohos.base'; 398 399let testMissionId = 1; 400try { 401 missionManager.getMissionInfo('', testMissionId).then((data) => { 402 console.info(`getMissionInfo successfully. Data: ${JSON.stringify(data)}`); 403 }).catch((error: BusinessError) => { 404 console.error(`getMissionInfo failed. Cause: ${error.message}`); 405 }); 406} catch (error) { 407 console.error(`getMissionInfo failed. Cause: ${error.message}`); 408} 409``` 410 411## missionManager.getMissionInfos 412 413getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void; 414 415Obtains information about all missions. This API uses an asynchronous callback to return the result. 416 417**Required permissions**: ohos.permission.MANAGE_MISSIONS 418 419**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 420 421**System API**: This is a system API and cannot be called by third-party applications. 422 423**Parameters** 424 425 | Name| Type| Mandatory| Description| 426 | -------- | -------- | -------- | -------- | 427 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 428 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 429 | callback | AsyncCallback<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.| 430 431**Example** 432 433 ```ts 434 import missionManager from '@ohos.app.ability.missionManager'; 435 import { BusinessError } from '@ohos.base'; 436 437 try { 438 missionManager.getMissionInfos('', 10, (error, missions) => { 439 if (error) { 440 console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`); 441 } else { 442 console.log(`size = ${missions.length}`); 443 console.log(`missions = ${JSON.stringify(missions)}`); 444 } 445 }); 446 } catch (paramError) { 447 let code = (paramError as BusinessError).code; 448 let message = (paramError as BusinessError).message; 449 console.error(`error: ${code}, ${message} `); 450 } 451 ``` 452 453 454## missionManager.getMissionInfos 455 456getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>; 457 458Obtains information about all missions. This API uses a promise to return the result. 459 460**Required permissions**: ohos.permission.MANAGE_MISSIONS 461 462**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 463 464**System API**: This is a system API and cannot be called by third-party applications. 465 466**Parameters** 467 468 | Name| Type| Mandatory| Description| 469 | -------- | -------- | -------- | -------- | 470 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 471 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 472 473**Return value** 474 475 | Type| Description| 476 | -------- | -------- | 477 | Promise<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.| 478 479**Example** 480 481```ts 482import missionManager from '@ohos.app.ability.missionManager'; 483import { BusinessError } from '@ohos.base'; 484 485try { 486 missionManager.getMissionInfos('', 10).then((data) => { 487 console.info('getMissionInfos successfully. Data: ${JSON.stringify(data)}'); 488 }).catch((error: BusinessError) => { 489 console.error('getMissionInfos failed. Cause: ${error.message}'); 490 }); 491} catch (error) { 492 console.error('getMissionInfos failed. Cause: ${error.message}'); 493} 494``` 495 496## missionManager.getMissionSnapShot 497 498getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void; 499 500Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result. 501 502**Required permissions**: ohos.permission.MANAGE_MISSIONS 503 504**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 505 506**System API**: This is a system API and cannot be called by third-party applications. 507 508**Parameters** 509 510 | Name| Type| Mandatory| Description| 511 | -------- | -------- | -------- | -------- | 512 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 513 | missionId | number | Yes| Mission ID.| 514 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 515 516**Example** 517```ts 518import missionManager from '@ohos.app.ability.missionManager'; 519 520let testMissionId = 2; 521try { 522 missionManager.getMissionSnapShot('', testMissionId, (err, data) => { 523 if (err) { 524 console.error(`getMissionSnapShot failed: ${err.message}`); 525 } else { 526 console.info(`getMissionSnapShot successfully: ${JSON.stringify(data)}`); 527 } 528 }); 529} catch (err) { 530 console.error(`getMissionSnapShot failed: ${err.message}`); 531} 532``` 533 534## missionManager.getMissionSnapShot 535 536getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>; 537 538Obtains the snapshot of a given mission. This API uses a promise to return the result. 539 540**Required permissions**: ohos.permission.MANAGE_MISSIONS 541 542**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 543 544**System API**: This is a system API and cannot be called by third-party applications. 545 546**Parameters** 547 548 | Name| Type| Mandatory| Description| 549 | -------- | -------- | -------- | -------- | 550 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 551 | missionId | number | Yes| Mission ID.| 552 553**Return value** 554 555 | Type| Description| 556 | -------- | -------- | 557 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 558 559**Example** 560```ts 561import missionManager from '@ohos.app.ability.missionManager'; 562import { BusinessError } from '@ohos.base'; 563 564let testMissionId = 2; 565try { 566 missionManager.getMissionSnapShot('', testMissionId).then((data) => { 567 console.info(`getMissionSnapShot successfully. Data: ${JSON.stringify(data)}`); 568 }).catch((error: BusinessError) => { 569 console.error(`getMissionSnapShot failed. Cause: ${error.message}`); 570 }); 571} catch (error) { 572 console.error(`getMissionSnapShot failed. Cause: ${error.message}`); 573} 574``` 575 576## missionManager.getLowResolutionMissionSnapShot 577 578getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void; 579 580Obtains the low-resolution snapshot of a given mission. This API uses an asynchronous callback to return the result. 581 582**Required permissions**: ohos.permission.MANAGE_MISSIONS 583 584**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 585 586**System API**: This is a system API and cannot be called by third-party applications. 587 588**Parameters** 589 590 | Name| Type| Mandatory| Description| 591 | -------- | -------- | -------- | -------- | 592 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 593 | missionId | number | Yes| Mission ID.| 594 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 595 596**Example** 597```ts 598import missionManager from '@ohos.app.ability.missionManager'; 599 600let testMissionId = 2; 601try { 602 missionManager.getLowResolutionMissionSnapShot('', testMissionId, (err, data) => { 603 if (err) { 604 console.error(`getLowResolutionMissionSnapShot failed: ${err.message}`); 605 } else { 606 console.info(`getLowResolutionMissionSnapShot successfully: ${JSON.stringify(data)}`); 607 } 608 }); 609} catch (err) { 610 console.error(`getLowResolutionMissionSnapShot failed: ${err.message}`); 611} 612``` 613 614## missionManager.getLowResolutionMissionSnapShot 615 616getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot>; 617 618Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result. 619 620**Required permissions**: ohos.permission.MANAGE_MISSIONS 621 622**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 623 624**System API**: This is a system API and cannot be called by third-party applications. 625 626**Parameters** 627 628 | Name| Type| Mandatory| Description| 629 | -------- | -------- | -------- | -------- | 630 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 631 | missionId | number | Yes| Mission ID.| 632 633**Return value** 634 635 | Type| Description| 636 | -------- | -------- | 637 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 638 639**Example** 640 641```ts 642import missionManager from '@ohos.app.ability.missionManager'; 643import { BusinessError } from '@ohos.base'; 644 645let testMissionId = 2; 646try { 647 missionManager.getLowResolutionMissionSnapShot('', testMissionId).then((data) => { 648 console.info(`getLowResolutionMissionSnapShot successfully. Data: ${JSON.stringify(data)}`); 649 }).catch((error: BusinessError) => { 650 console.error(`getLowResolutionMissionSnapShot failed. Cause: ${error.message}`); 651 }); 652} catch (error) { 653 console.error(`getLowResolutionMissionSnapShot failed. Cause: ${error.message}`); 654} 655``` 656 657 658## missionManager.lockMission 659 660lockMission(missionId: number, callback: AsyncCallback<void>): void; 661 662Locks a given mission. This API uses an asynchronous callback to return the result. 663 664**Required permissions**: ohos.permission.MANAGE_MISSIONS 665 666**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 667 668**System API**: This is a system API and cannot be called by third-party applications. 669 670**Parameters** 671 672 | Name| Type| Mandatory| Description| 673 | -------- | -------- | -------- | -------- | 674 | missionId | number | Yes| Mission ID.| 675 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 676 677**Error codes** 678 679| ID| Error Message| 680| ------- | -------- | 681| 16300001 | Mission not found. | 682 683For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 684 685**Example** 686 687```ts 688import missionManager from '@ohos.app.ability.missionManager'; 689 690let testMissionId = 2; 691try { 692 missionManager.lockMission(testMissionId, (err, data) => { 693 if (err) { 694 console.error(`lockMission failed: ${err.message}`); 695 } else { 696 console.info(`lockMission successfully: ${JSON.stringify(data)}`); 697 } 698 }); 699} catch (err) { 700 console.error(`lockMission failed: ${err.message}`); 701} 702``` 703 704## missionManager.lockMission 705 706lockMission(missionId: number): Promise<void>; 707 708Locks a given mission. This API uses a promise to return the result. 709 710**Required permissions**: ohos.permission.MANAGE_MISSIONS 711 712**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 713 714**System API**: This is a system API and cannot be called by third-party applications. 715 716**Parameters** 717 718 | Name| Type| Mandatory| Description| 719 | -------- | -------- | -------- | -------- | 720 | missionId | number | Yes| Mission ID.| 721 722**Return value** 723 724 | Type| Description| 725 | -------- | -------- | 726 | Promise<void> | Promise used to return the result.| 727 728**Error codes** 729 730| ID| Error Message| 731| ------- | -------- | 732| 16300001 | Mission not found. | 733 734For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 735 736**Example** 737```ts 738import missionManager from '@ohos.app.ability.missionManager'; 739import { BusinessError } from '@ohos.base'; 740 741let testMissionId = 2; 742try { 743 missionManager.lockMission(testMissionId).then((data) => { 744 console.info(`lockMission successfully. Data: ${JSON.stringify(data)}`); 745 }).catch((error: BusinessError) => { 746 console.error(`lockMission failed. Cause: ${error.message}`); 747 }); 748} catch (error) { 749 console.error(`lockMission failed. Cause: ${error.message}`); 750} 751``` 752 753## missionManager.unlockMission 754 755unlockMission(missionId: number, callback: AsyncCallback<void>): void; 756 757Unlocks a given mission. This API uses an asynchronous callback to return the result. 758 759**Required permissions**: ohos.permission.MANAGE_MISSIONS 760 761**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 762 763**System API**: This is a system API and cannot be called by third-party applications. 764 765**Parameters** 766 767| Name| Type| Mandatory| Description| 768| -------- | -------- | -------- | -------- | 769| missionId | number | Yes| Mission ID.| 770| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 771 772**Error codes** 773 774| ID| Error Message| 775| ------- | -------- | 776| 16300001 | Mission not found. | 777 778For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 779 780**Example** 781```ts 782import missionManager from '@ohos.app.ability.missionManager'; 783 784let testMissionId = 2; 785try { 786 missionManager.unlockMission(testMissionId, (err, data) => { 787 if (err) { 788 console.error(`unlockMission failed: ${err.message}`); 789 } else { 790 console.info(`unlockMission successfully: ${JSON.stringify(data)}`); 791 } 792 }); 793} catch (err) { 794 console.error(`unlockMission failed: ${err.message}`); 795} 796``` 797 798## missionManager.unlockMission 799 800unlockMission(missionId: number): Promise<void>; 801 802Unlocks a given mission. This API uses a promise to return the result. 803 804**Required permissions**: ohos.permission.MANAGE_MISSIONS 805 806**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 807 808**System API**: This is a system API and cannot be called by third-party applications. 809 810**Parameters** 811 812 | Name| Type| Mandatory| Description| 813 | -------- | -------- | -------- | -------- | 814 | missionId | number | Yes| Mission ID.| 815 816**Return value** 817 818 | Type| Description| 819 | -------- | -------- | 820 | Promise<void> | Promise used to return the result.| 821 822**Error codes** 823 824| ID| Error Message| 825| ------- | -------- | 826| 16300001 | Mission not found. | 827 828For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 829 830**Example** 831 832```ts 833import missionManager from '@ohos.app.ability.missionManager'; 834import { BusinessError } from '@ohos.base'; 835 836let testMissionId = 2; 837try { 838 missionManager.unlockMission(testMissionId).then((data) => { 839 console.info(`unlockMission successfully. Data: ${JSON.stringify(data)}`); 840 }).catch((error: BusinessError) => { 841 console.error(`unlockMission failed. Cause: ${error.message}`); 842 }); 843} catch (error) { 844 console.error(`unlockMission failed. Cause: ${error.message}`); 845} 846``` 847 848## missionManager.clearMission 849 850clearMission(missionId: number, callback: AsyncCallback<void>): void; 851 852Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result. 853 854**Required permissions**: ohos.permission.MANAGE_MISSIONS 855 856**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 857 858**System API**: This is a system API and cannot be called by third-party applications. 859 860**Parameters** 861 862 | Name| Type| Mandatory| Description| 863 | -------- | -------- | -------- | -------- | 864 | missionId | number | Yes| Mission ID.| 865 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 866 867**Example** 868 869```ts 870import missionManager from '@ohos.app.ability.missionManager'; 871 872let testMissionId = 2; 873try { 874 missionManager.clearMission(testMissionId, (err, data) => { 875 if (err) { 876 console.error(`clearMission failed: ${err.message}`); 877 } else { 878 console.info(`clearMission successfully: ${JSON.stringify(data)}`); 879 } 880 }); 881} catch (err) { 882 console.error(`clearMission failed: ${err.message}`); 883} 884``` 885 886 887## missionManager.clearMission 888 889clearMission(missionId: number): Promise<void>; 890 891Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result. 892 893**Required permissions**: ohos.permission.MANAGE_MISSIONS 894 895**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 896 897**System API**: This is a system API and cannot be called by third-party applications. 898 899**Parameters** 900 901 | Name| Type| Mandatory| Description| 902 | -------- | -------- | -------- | -------- | 903 | missionId | number | Yes| Mission ID.| 904 905**Return value** 906 907 | Type| Description| 908 | -------- | -------- | 909 | Promise<void> | Promise used to return the result.| 910 911**Example** 912 913```ts 914import missionManager from '@ohos.app.ability.missionManager'; 915import { BusinessError } from '@ohos.base'; 916 917let testMissionId = 2; 918try { 919 missionManager.clearMission(testMissionId).then((data) => { 920 console.info(`clearMission successfully. Data: ${JSON.stringify(data)}`); 921 }).catch((error: BusinessError) => { 922 console.error(`clearMission failed. Cause: ${error.message}`); 923 }); 924} catch (error) { 925 console.error(`clearMission failed. Cause: ${error.message}`); 926} 927``` 928 929## missionManager.clearAllMissions 930 931clearAllMissions(callback: AsyncCallback<void>): void; 932 933Clears all unlocked missions. This API uses an asynchronous callback to return the result. 934 935**Required permissions**: ohos.permission.MANAGE_MISSIONS 936 937**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 938 939**System API**: This is a system API and cannot be called by third-party applications. 940 941**Example** 942 943```ts 944import missionManager from '@ohos.app.ability.missionManager'; 945 946try { 947 missionManager.clearAllMissions(err => { 948 if (err) { 949 console.error('clearAllMissions failed: ${err.message}'); 950 } else { 951 console.info('clearAllMissions successfully.'); 952 } 953 }); 954} catch (err) { 955 console.error('clearAllMissions failed: ${err.message}'); 956} 957``` 958 959## missionManager.clearAllMissions 960 961clearAllMissions(): Promise<void>; 962 963Clears all unlocked missions. This API uses a promise to return the result. 964 965**Required permissions**: ohos.permission.MANAGE_MISSIONS 966 967**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 968 969**System API**: This is a system API and cannot be called by third-party applications. 970 971**Return value** 972 973 | Type| Description| 974 | -------- | -------- | 975 | Promise<void> | Promise used to return the result.| 976 977**Example** 978 979```ts 980import missionManager from '@ohos.app.ability.missionManager'; 981import { BusinessError } from '@ohos.base'; 982 983try { 984 missionManager.clearAllMissions().then((data) => { 985 console.info(`clearAllMissions successfully. Data: ${JSON.stringify(data)}`); 986 }).catch((err: BusinessError) => { 987 console.error(`clearAllMissions failed: ${err.message}`); 988 }); 989} catch (err) { 990 console.error(`clearAllMissions failed: ${err.message}`); 991} 992``` 993 994## missionManager.moveMissionToFront 995 996moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void; 997 998Switches a given mission to the foreground. This API uses an asynchronous callback to return the result. 999 1000**Required permissions**: ohos.permission.MANAGE_MISSIONS 1001 1002**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1003 1004**System API**: This is a system API and cannot be called by third-party applications. 1005 1006**Parameters** 1007 1008 | Name| Type| Mandatory| Description| 1009 | -------- | -------- | -------- | -------- | 1010 | missionId | number | Yes| Mission ID.| 1011 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1012 1013**Error codes** 1014 1015| ID| Error Message| 1016| ------- | -------- | 1017| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1018 1019For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1020 1021**Example** 1022 1023```ts 1024import missionManager from '@ohos.app.ability.missionManager'; 1025 1026let testMissionId = 2; 1027try { 1028 missionManager.moveMissionToFront(testMissionId, (err, data) => { 1029 if (err) { 1030 console.error(`moveMissionToFront failed: ${err.message}`); 1031 } else { 1032 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 1033 } 1034 }); 1035} catch (err) { 1036 console.error(`moveMissionToFront failed: ${err.message}`); 1037} 1038``` 1039 1040## missionManager.moveMissionToFront 1041 1042moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void; 1043 1044Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result. 1045 1046**Required permissions**: ohos.permission.MANAGE_MISSIONS 1047 1048**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1049 1050**System API**: This is a system API and cannot be called by third-party applications. 1051 1052**Parameters** 1053 1054 | Name| Type| Mandatory| Description| 1055 | -------- | -------- | -------- | -------- | 1056 | missionId | number | Yes| Mission ID.| 1057 | 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.| 1058 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1059 1060**Error codes** 1061 1062| ID| Error Message| 1063| ------- | -------- | 1064| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1065 1066For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1067 1068**Example** 1069 1070```ts 1071import missionManager from '@ohos.app.ability.missionManager'; 1072 1073let testMissionId = 2; 1074try { 1075 missionManager.moveMissionToFront(testMissionId, {windowMode : 101}, (err, data) => { 1076 if (err) { 1077 console.error(`moveMissionToFront failed: ${err.message}`); 1078 } else { 1079 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 1080 } 1081 }); 1082} catch (err) { 1083 console.error(`moveMissionToFront failed: ${err.message}`); 1084} 1085``` 1086 1087## missionManager.moveMissionToFront 1088 1089moveMissionToFront(missionId: number, options?: StartOptions): Promise<void>; 1090 1091Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result. 1092 1093**Required permissions**: ohos.permission.MANAGE_MISSIONS 1094 1095**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1096 1097**System API**: This is a system API and cannot be called by third-party applications. 1098 1099**Parameters** 1100 1101 | Name| Type| Mandatory| Description| 1102 | -------- | -------- | -------- | -------- | 1103 | missionId | number | Yes| Mission ID.| 1104 | 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. By default, no value is passed in, indicating that the default startup parameters are used.| 1105 1106**Return value** 1107 1108 | Type| Description| 1109 | -------- | -------- | 1110 | Promise<void> | Promise used to return the result.| 1111 1112**Error codes** 1113 1114| ID| Error Message| 1115| ------- | -------- | 1116| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1117 1118For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1119 1120**Example** 1121 1122```ts 1123import missionManager from '@ohos.app.ability.missionManager'; 1124import { BusinessError } from '@ohos.base'; 1125 1126let testMissionId = 2; 1127try { 1128 missionManager.moveMissionToFront(testMissionId).then((data) => { 1129 console.info(`moveMissionToFront successfully. Data: ${JSON.stringify(data)}`); 1130 }).catch((error: BusinessError) => { 1131 console.error(`moveMissionToFront failed. Cause: ${error.message}`); 1132 }); 1133} catch (error) { 1134 console.error(`moveMissionToFront failed. Cause: ${error.message}`); 1135} 1136``` 1137 1138## missionManager.moveMissionsToForeground<sup>10+</sup> 1139 1140moveMissionsToForeground(missionIds: Array<number>, callback: AsyncCallback<void>): void; 1141 1142Switches a batch of missions to the foreground. This API uses an asynchronous callback to return the result. 1143 1144**Required permissions**: ohos.permission.MANAGE_MISSIONS 1145 1146**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1147 1148**System API**: This is a system API. 1149 1150**Parameters** 1151 1152 | Name| Type| Mandatory| Description| 1153 | -------- | -------- | -------- | -------- | 1154 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1155 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1156 1157**Error codes** 1158 1159For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1160 1161| ID| Error Message| 1162| ------- | -------- | 1163| 16000050 | Internal error. | 1164 1165**Example** 1166 1167```ts 1168import abilityManager from '@ohos.app.ability.abilityManager'; 1169import missionManager from '@ohos.app.ability.missionManager'; 1170import { BusinessError } from '@ohos.base'; 1171 1172try { 1173 missionManager.getMissionInfos("", 10, (error, missionInfos) => { 1174 if (error.code) { 1175 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1176 return; 1177 } 1178 if (missionInfos.length < 1) { 1179 return; 1180 } 1181 1182 let toShows = new Array<number>(); 1183 for (let missionInfo of missionInfos) { 1184 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1185 toShows.push(missionInfo.missionId); 1186 } 1187 } 1188 missionManager.moveMissionsToForeground(toShows, (err, data) => { 1189 if (err) { 1190 console.error(`moveMissionsToForeground failed: ${err.message}`); 1191 } else { 1192 console.info(`moveMissionsToForeground successfully: ${JSON.stringify(data)}`); 1193 } 1194 }); 1195 }); 1196} catch (paramError) { 1197 let code = (paramError as BusinessError).code; 1198 let message = (paramError as BusinessError).message; 1199 console.error(`error: ${code}, ${message} `); 1200} 1201 1202``` 1203 1204## missionManager.moveMissionsToForeground<sup>10+</sup> 1205 1206moveMissionsToForeground(missionIds: Array<number>, topMission: number, callback: AsyncCallback<void>): void; 1207 1208Switches a batch of missions to the foreground, and moves the mission with the specified ID to the top. This API uses an asynchronous callback to return the result. 1209 1210**Required permissions**: ohos.permission.MANAGE_MISSIONS 1211 1212**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1213 1214**System API**: This is a system API. 1215 1216**Parameters** 1217 1218 | Name| Type| Mandatory| Description| 1219 | -------- | -------- | -------- | -------- | 1220 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1221 | topMission | number | Yes| ID of the mission to be moved to the top.| 1222 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1223 1224**Error codes** 1225 1226For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1227 1228| ID| Error Message| 1229| ------- | -------- | 1230| 16000050 | Internal error. | 1231 1232**Example** 1233 1234```ts 1235import abilityManager from '@ohos.app.ability.abilityManager'; 1236import missionManager from '@ohos.app.ability.missionManager'; 1237import { BusinessError } from '@ohos.base'; 1238 1239try { 1240 missionManager.getMissionInfos("", 10, (error, missionInfos) => { 1241 if (error.code) { 1242 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1243 return; 1244 } 1245 if (missionInfos.length < 1) { 1246 return; 1247 } 1248 1249 let toShows = new Array<number>(); 1250 for (let missionInfo of missionInfos) { 1251 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1252 toShows.push(missionInfo.missionId); 1253 } 1254 } 1255 missionManager.moveMissionsToForeground(toShows, toShows[0], (err, data) => { 1256 if (err) { 1257 console.error(`moveMissionsToForeground failed: ${err.message}`); 1258 } else { 1259 console.info(`moveMissionsToForeground successfully: ${JSON.stringify(data)}`); 1260 } 1261 }); 1262 }); 1263} catch (paramError) { 1264 let code = (paramError as BusinessError).code; 1265 let message = (paramError as BusinessError).message; 1266 console.error(`error: ${code}, ${message} `); 1267} 1268 1269``` 1270 1271## missionManager.moveMissionsToForeground<sup>10+</sup> 1272 1273moveMissionsToForeground(missionIds: Array<number>, topMission?: number): Promise<void> ; 1274 1275Switches a batch of missions to the foreground, and moves the mission with the specified ID to the top. This API uses a promise to return the result. 1276 1277**Required permissions**: ohos.permission.MANAGE_MISSIONS 1278 1279**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1280 1281**System API**: This is a system API. 1282 1283**Parameters** 1284 1285 | Name| Type| Mandatory| Description| 1286 | -------- | -------- | -------- | -------- | 1287 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1288 | topMission | number | No| ID of the mission to be moved to the top. The default value is **-1**, indicating that the default mission is moved to the top.| 1289 1290**Return value** 1291 1292 | Type| Description| 1293 | -------- | -------- | 1294 | Promise<void> | Promise used to return the result.| 1295 1296**Error codes** 1297 1298For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1299 1300| ID| Error Message| 1301| ------- | -------- | 1302| 16000050 | Internal error. | 1303 1304**Example** 1305 1306```ts 1307import abilityManager from '@ohos.app.ability.abilityManager'; 1308import missionManager from '@ohos.app.ability.missionManager'; 1309import { BusinessError } from '@ohos.base'; 1310 1311try { 1312 missionManager.getMissionInfos("", 10, (error, missionInfos) => { 1313 if (error.code) { 1314 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1315 return; 1316 } 1317 if (missionInfos.length < 1) { 1318 return; 1319 } 1320 1321 let toShows = new Array<number>(); 1322 for (let missionInfo of missionInfos) { 1323 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1324 toShows.push(missionInfo.missionId); 1325 } 1326 } 1327 missionManager.moveMissionsToForeground(toShows, toShows[0]).then(() => { 1328 console.log("moveMissionsToForeground is called" ); 1329 }); 1330 }); 1331} catch (paramError) { 1332 let code = (paramError as BusinessError).code; 1333 let message = (paramError as BusinessError).message; 1334 console.error(`error: ${code}, ${message} `); 1335} 1336 1337``` 1338 1339## missionManager.moveMissionsToBackground<sup>10+</sup> 1340 1341moveMissionsToBackground(missionIds: Array<number>, callback: AsyncCallback<Array<number>>): void; 1342 1343Switches a batch of missions to the background. This API uses an asynchronous callback to return the result. The mission IDs in the callback are sorted by mission level when the missions are switched. 1344 1345**Required permissions**: ohos.permission.MANAGE_MISSIONS 1346 1347**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1348 1349**System API**: This is a system API. 1350 1351**Parameters** 1352 1353 | Name| Type| Mandatory| Description| 1354 | -------- | -------- | -------- | -------- | 1355 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1356 | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the result.| 1357 1358**Error codes** 1359 1360For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1361 1362| ID| Error Message| 1363| ------- | -------- | 1364| 16000050 | Internal error. | 1365 1366**Example** 1367 1368```ts 1369import abilityManager from '@ohos.app.ability.abilityManager'; 1370import missionManager from '@ohos.app.ability.missionManager'; 1371import { BusinessError } from '@ohos.base'; 1372 1373try { 1374 missionManager.getMissionInfos("", 10, (error, missionInfos) => { 1375 if (error.code) { 1376 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1377 return; 1378 } 1379 1380 let toHides = new Array<number>(); 1381 for (let missionInfo of missionInfos) { 1382 if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { 1383 toHides.push(missionInfo.missionId); 1384 } 1385 } 1386 missionManager.moveMissionsToBackground(toHides, (err, data) => { 1387 if (err) { 1388 console.error(`moveMissionsToBackground failed: ${err.message}`); 1389 } else { 1390 console.info(`moveMissionsToBackground successfully: ${JSON.stringify(data)}`); 1391 } 1392 }); 1393 }); 1394} catch (paramError) { 1395 let code = (paramError as BusinessError).code; 1396 let message = (paramError as BusinessError).message; 1397 console.error(`error: ${code}, ${message} `); 1398} 1399``` 1400 1401## missionManager.moveMissionsToBackground<sup>10+</sup> 1402 1403moveMissionsToBackground(missionIds : Array<number>): Promise<Array<number>>; 1404 1405Switches a batch of missions to the background. This API uses a promise to return the result. The mission IDs in the promise are sorted by mission level when the missions are switched. 1406 1407**Required permissions**: ohos.permission.MANAGE_MISSIONS 1408 1409**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1410 1411**System API**: This is a system API. 1412 1413**Parameters** 1414 1415 | Name| Type| Mandatory| Description| 1416 | -------- | -------- | -------- | -------- | 1417 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1418 1419**Return value** 1420 1421 | Type| Description| 1422 | -------- | -------- | 1423 | Promise<Array<number>> | Promise used to return the result.| 1424 1425**Error codes** 1426 1427For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1428 1429| ID| Error Message| 1430| ------- | -------- | 1431| 16000050 | Internal error. | 1432 1433**Example** 1434 1435```ts 1436import abilityManager from '@ohos.app.ability.abilityManager'; 1437import missionManager from '@ohos.app.ability.missionManager'; 1438import { BusinessError } from '@ohos.base'; 1439 1440try { 1441 missionManager.getMissionInfos("", 10, (error, missionInfos) => { 1442 if (error.code) { 1443 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1444 return; 1445 } 1446 1447 let toHides = new Array<number>(); 1448 for (let missionInfo of missionInfos) { 1449 if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { 1450 toHides.push(missionInfo.missionId); 1451 } 1452 } 1453 missionManager.moveMissionsToBackground(toHides).then((hideRes) => { 1454 console.log("moveMissionsToBackground is called, res: "+ JSON.stringify(hideRes)); 1455 }); 1456 }); 1457} catch (paramError) { 1458 let code = (paramError as BusinessError).code; 1459 let message = (paramError as BusinessError).message; 1460 console.error(`error: ${code}, ${message} `); 1461} 1462 1463``` 1464