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