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