• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.missionManager (missionManager)
2
3The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import missionManager from '@ohos.app.ability.missionManager';
13```
14
15## Required Permissions
16
17ohos.permission.MANAGE_MISSIONS
18
19## missionManager.on
20
21on(type:'mission', listener: MissionListener): number;
22
23Registers a listener to observe the mission status.
24
25**Required permissions**: ohos.permission.MANAGE_MISSIONS
26
27**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
28
29**System API**: This is a system API and cannot be called by third-party applications.
30
31**Parameters**
32
33  | Name| Type| Mandatory| Description|
34  | -------- | -------- | -------- | -------- |
35  | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.|
36
37**Return value**
38
39  | Type| Description|
40  | -------- | -------- |
41  | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.|
42
43**Example**
44
45```ts
46import missionManager from '@ohos.app.ability.missionManager';
47import UIAbility from '@ohos.app.ability.UIAbility';
48
49let listener = {
50    onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
51    onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
52    onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
53    onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
54    onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
55    onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
56    onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
57};
58
59let listenerId = -1;
60
61export default class EntryAbility extends UIAbility {
62    onCreate(want, launchParam) {
63        console.log('[Demo] EntryAbility onCreate');
64        globalThis.abilityWant = want;
65        globalThis.context = this.context;
66    }
67
68    onDestroy() {
69        try {
70            if (listenerId !== -1) {
71                missionManager.off('mission', listenerId).catch(function (err) {
72                    console.log(err);
73                });
74            }
75        } catch (paramError) {
76            console.error('error: ${paramError.code}, ${paramError.message}');
77        }
78        console.log('[Demo] EntryAbility onDestroy');
79    }
80
81    onWindowStageCreate(windowStage) {
82        // The main window is created. Set a main page for this ability.
83        console.log('[Demo] EntryAbility onWindowStageCreate');
84        try {
85            listenerId = missionManager.on('mission', listener);
86        } catch (paramError) {
87            console.error('error: ${paramError.code}, ${paramError.message}');
88        }
89
90        windowStage.loadContent('pages/index', (err, data) => {
91            if (err.code) {
92                console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
93                return;
94            }
95            console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
96        });
97
98        if (globalThis.flag) {
99            return;
100        }
101    }
102};
103```
104
105
106## missionManager.off
107
108off(type: 'mission', listenerId: number, callback: AsyncCallback<void>): void;
109
110Deregisters a mission status listener. This API uses an asynchronous callback to return the result.
111
112**Required permissions**: ohos.permission.MANAGE_MISSIONS
113
114**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
115
116**System API**: This is a system API and cannot be called by third-party applications.
117
118**Parameters**
119
120  | Name| Type| Mandatory| Description|
121  | -------- | -------- | -------- | -------- |
122  | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.|
123  | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
124
125**Error codes**
126
127| ID| Error Message|
128| ------- | -------- |
129| 16300002 | Input error. The specified mission listener does not exist. |
130
131For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
132
133**Example**
134
135```ts
136import missionManager from '@ohos.app.ability.missionManager';
137import UIAbility from '@ohos.app.ability.UIAbility';
138
139let listener = {
140    onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
141    onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
142    onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
143    onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
144    onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
145    onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
146    onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
147};
148
149let listenerId = -1;
150
151export default class EntryAbility extends UIAbility {
152    onCreate(want, launchParam) {
153        console.log('[Demo] EntryAbility onCreate');
154        globalThis.abilityWant = want;
155        globalThis.context = this.context;
156    }
157
158    onDestroy() {
159        try {
160            if (listenerId !== -1) {
161                missionManager.off('mission', listenerId, (err) => {
162                    console.log(err);
163                });
164            }
165        } catch (paramError) {
166            console.error('error: ${paramError.code}, ${paramError.message}');
167        }
168        console.log('[Demo] EntryAbility onDestroy');
169    }
170
171    onWindowStageCreate(windowStage) {
172        // The main window is created. Set a main page for this ability.
173        console.log('[Demo] EntryAbility onWindowStageCreate');
174        try {
175            listenerId = missionManager.on('mission', listener);
176        } catch (paramError) {
177            console.error('error: ${paramError.code}, ${paramError.message}');
178        }
179
180        windowStage.loadContent('pages/index', (err, data) => {
181            if (err.code) {
182                console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
183                return;
184            }
185            console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
186        });
187
188        if (globalThis.flag) {
189            return;
190        }
191    }
192};
193```
194
195
196## missionManager.off
197
198off(type: 'mission', listenerId: number): Promise<void>;
199
200Deregisters a mission status listener. This API uses a promise to return the result.
201
202**Required permissions**: ohos.permission.MANAGE_MISSIONS
203
204**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
205
206**System API**: This is a system API and cannot be called by third-party applications.
207
208**Parameters**
209
210  | Name| Type| Mandatory| Description|
211  | -------- | -------- | -------- | -------- |
212  | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.|
213
214**Return value**
215
216  | Type| Description|
217  | -------- | -------- |
218  | Promise<void> | Promise used to return the result.|
219
220**Error codes**
221
222| ID| Error Message|
223| ------- | -------- |
224| 16300002 | Input error. The specified mission listener does not exist. |
225
226For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
227
228**Example**
229
230```ts
231import missionManager from '@ohos.app.ability.missionManager';
232import UIAbility from '@ohos.app.ability.UIAbility';
233
234let listener = {
235    onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');},
236    onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');},
237    onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');},
238    onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');},
239    onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');},
240    onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');},
241    onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
242};
243
244let listenerId = -1;
245
246export default class EntryAbility extends UIAbility {
247    onCreate(want, launchParam) {
248        console.log('[Demo] EntryAbility onCreate');
249        globalThis.abilityWant = want;
250        globalThis.context = this.context;
251    }
252
253    onDestroy() {
254        try {
255            if (listenerId !== -1) {
256                missionManager.off('mission', listenerId).catch(function (err) {
257                    console.log(err);
258                });
259            }
260        } catch (paramError) {
261            console.error('error: ${paramError.code}, ${paramError.message}');
262        }
263        console.log('[Demo] EntryAbility onDestroy');
264    }
265
266    onWindowStageCreate(windowStage) {
267        // The main window is created. Set a main page for this ability.
268        console.log('[Demo] EntryAbility onWindowStageCreate');
269        try {
270            listenerId = missionManager.on('mission', listener);
271        } catch (paramError) {
272            console.error('error: ${paramError.code}, ${paramError.message}');
273        }
274
275        windowStage.loadContent('pages/index', (err, data) => {
276            if (err.code) {
277                console.error('Failed to load the content. Cause: ${JSON.stringify(err)}');
278                return;
279            }
280            console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}');
281        });
282
283        if (globalThis.flag) {
284            return;
285        }
286    }
287};
288```
289
290
291## missionManager.getMissionInfo
292
293getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void;
294
295Obtains the information about a given mission. This API uses an asynchronous callback to return the result.
296
297**Required permissions**: ohos.permission.MANAGE_MISSIONS
298
299**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
300
301**System API**: This is a system API and cannot be called by third-party applications.
302
303**Parameters**
304
305  | Name| Type| Mandatory| Description|
306  | -------- | -------- | -------- | -------- |
307  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
308  | missionId | number | Yes| Mission ID.|
309  | callback | AsyncCallback<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.|
310
311**Example**
312
313  ```ts
314    import missionManager from '@ohos.app.ability.missionManager';
315
316    let testMissionId = 1;
317
318    missionManager.getMissionInfos('',10)
319    .then((allMissions) => {
320        try {
321        if (allMissions && allMissions.length > 0) {
322            testMissionId = allMissions[0].missionId;
323        }
324
325        missionManager.getMissionInfo('', testMissionId, (error, mission) => {
326            if (error) {
327            console.error('getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}');
328            } else {
329            console.log('mission.missionId = ${mission.missionId}');
330            console.log('mission.runningState = ${mission.runningState}');
331            console.log('mission.lockedState = ${mission.lockedState}');
332            console.log('mission.timestamp = ${mission.timestamp}');
333            console.log('mission.label = ${mission.label}');
334            console.log('mission.iconPath = ${mission.iconPath}');
335            }
336        });
337        } catch (paramError) {
338        console.error('error.code: ${paramError.code}, error.message: ${paramError.message}');
339        }
340    })
341    .catch(function(err){console.log(err);});
342  ```
343
344## missionManager.getMissionInfo
345
346getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>;
347
348Obtains the information about a given mission. This API uses a promise to return the result.
349
350**Required permissions**: ohos.permission.MANAGE_MISSIONS
351
352**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
353
354**System API**: This is a system API and cannot be called by third-party applications.
355
356**Parameters**
357
358  | Name| Type| Mandatory| Description|
359  | -------- | -------- | -------- | -------- |
360  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
361  | missionId | number | Yes| Mission ID.|
362
363**Return value**
364
365  | Type| Description|
366  | -------- | -------- |
367  | Promise<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.|
368
369**Example**
370
371```ts
372import missionManager from '@ohos.app.ability.missionManager';
373
374let testMissionId = 1;
375try {
376    missionManager.getMissionInfo('', testMissionId).then((data) => {
377        console.info('getMissionInfo successfully. Data: ${JSON.stringify(data)}');
378    }).catch(error => {
379        console.error('getMissionInfo failed. Cause: ${error.message}');
380    });
381} catch (error) {
382    console.error('getMissionInfo failed. Cause: ${error.message}');
383}
384```
385
386## missionManager.getMissionInfos
387
388getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void;
389
390Obtains information about all missions. This API uses an asynchronous callback to return the result.
391
392**Required permissions**: ohos.permission.MANAGE_MISSIONS
393
394**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
395
396**System API**: This is a system API and cannot be called by third-party applications.
397
398**Parameters**
399
400  | Name| Type| Mandatory| Description|
401  | -------- | -------- | -------- | -------- |
402  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
403  | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
404  | callback | AsyncCallback<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.|
405
406**Example**
407
408  ```ts
409  import missionManager from '@ohos.app.ability.missionManager';
410
411  try {
412    missionManager.getMissionInfos('', 10, (error, missions) => {
413      if (error) {
414          console.error('getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}');
415      } else {
416        console.log('size = ${missions.length}');
417        console.log('missions = ${JSON.stringify(missions)}');
418      }
419    });
420  } catch (paramError) {
421    console.error('error: ${paramError.code}, ${paramError.message}');
422  }
423  ```
424
425
426## missionManager.getMissionInfos
427
428getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>;
429
430Obtains information about all missions. This API uses a promise to return the result.
431
432**Required permissions**: ohos.permission.MANAGE_MISSIONS
433
434**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
435
436**System API**: This is a system API and cannot be called by third-party applications.
437
438**Parameters**
439
440  | Name| Type| Mandatory| Description|
441  | -------- | -------- | -------- | -------- |
442  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
443  | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
444
445**Return value**
446
447  | Type| Description|
448  | -------- | -------- |
449  | Promise<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.|
450
451**Example**
452
453```ts
454import missionManager from '@ohos.app.ability.missionManager';
455
456try {
457    missionManager.getMissionInfos('', 10).then((data) => {
458        console.info('getMissionInfos successfully. Data: ${JSON.stringify(data)}');
459    }).catch(error => {
460        console.error('getMissionInfos failed. Cause: ${error.message}');
461    });
462} catch (error) {
463    console.error('getMissionInfos failed. Cause: ${error.message}');
464}
465```
466
467## missionManager.getMissionSnapShot
468
469getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void;
470
471Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result.
472
473**Required permissions**: ohos.permission.MANAGE_MISSIONS
474
475**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
476
477**System API**: This is a system API and cannot be called by third-party applications.
478
479**Parameters**
480
481  | Name| Type| Mandatory| Description|
482  | -------- | -------- | -------- | -------- |
483  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
484  | missionId | number | Yes| Mission ID.|
485  | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
486
487**Example**
488```ts
489import missionManager from '@ohos.app.ability.missionManager';
490
491let testMissionId = 2;
492try {
493    missionManager.getMissionSnapShot('', testMissionId, (err, data) => {
494        if (err) {
495            console.error('getMissionSnapShot failed: ${err.message}');
496        } else {
497            console.info('getMissionSnapShot successfully: ${JSON.stringify(data)}');
498        }
499    });
500} catch (err) {
501    console.error('getMissionSnapShot failed: ${err.message}');
502}
503```
504
505## missionManager.getMissionSnapShot
506
507getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>;
508
509Obtains the snapshot of a given mission. This API uses a promise to return the result.
510
511**Required permissions**: ohos.permission.MANAGE_MISSIONS
512
513**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
514
515**System API**: This is a system API and cannot be called by third-party applications.
516
517**Parameters**
518
519  | Name| Type| Mandatory| Description|
520  | -------- | -------- | -------- | -------- |
521  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
522  | missionId | number | Yes| Mission ID.|
523
524**Return value**
525
526  | Type| Description|
527  | -------- | -------- |
528  | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.|
529
530**Example**
531```ts
532import missionManager from '@ohos.app.ability.missionManager';
533
534let testMissionId = 2;
535try {
536    missionManager.getMissionSnapShot('', testMissionId).then((data) => {
537        console.info('getMissionSnapShot successfully. Data: ${JSON.stringify(data)}');
538    }).catch(error => {
539        console.error('getMissionSnapShot failed. Cause: ${error.message}');
540    });
541} catch (error) {
542    console.error('getMissionSnapShot failed. Cause: ${error.message}');
543}
544```
545
546## missionManager.getLowResolutionMissionSnapShot
547
548getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void;
549
550Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result.
551
552**Required permissions**: ohos.permission.MANAGE_MISSIONS
553
554**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
555
556**System API**: This is a system API and cannot be called by third-party applications.
557
558**Parameters**
559
560  | Name| Type| Mandatory| Description|
561  | -------- | -------- | -------- | -------- |
562  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
563  | missionId | number | Yes| Mission ID.|
564  | callback | AsyncCallback&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|
565
566**Example**
567```ts
568import missionManager from '@ohos.app.ability.missionManager';
569
570let testMissionId = 2;
571try {
572    missionManager.getLowResolutionMissionSnapShot('', testMissionId, (err, data) => {
573        if (err) {
574            console.error('getLowResolutionMissionSnapShot failed: ${err.message}');
575        } else {
576            console.info('getLowResolutionMissionSnapShot successfully: ${JSON.stringify(data)}');
577        }
578    });
579} catch (err) {
580    console.error('getLowResolutionMissionSnapShot failed: ${err.message}');
581}
582```
583
584## missionManager.getLowResolutionMissionSnapShot
585
586getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot>;
587
588Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result.
589
590**Required permissions**: ohos.permission.MANAGE_MISSIONS
591
592**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
593
594**System API**: This is a system API and cannot be called by third-party applications.
595
596**Parameters**
597
598  | Name| Type| Mandatory| Description|
599  | -------- | -------- | -------- | -------- |
600  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
601  | missionId | number | Yes| Mission ID.|
602
603**Return value**
604
605  | Type| Description|
606  | -------- | -------- |
607  | Promise&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|
608
609**Example**
610
611```ts
612import missionManager from '@ohos.app.ability.missionManager';
613
614let testMissionId = 2;
615try {
616    missionManager.getLowResolutionMissionSnapShot('', testMissionId).then((data) => {
617        console.info('getLowResolutionMissionSnapShot successfully. Data: ${JSON.stringify(data)}');
618    }).catch(error => {
619        console.error('getLowResolutionMissionSnapShot failed. Cause: ${error.message}');
620    });
621} catch (error) {
622    console.error('getLowResolutionMissionSnapShot failed. Cause: ${error.message}');
623}
624```
625
626
627## missionManager.lockMission
628
629lockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
630
631Locks a given mission. This API uses an asynchronous callback to return the result.
632
633**Required permissions**: ohos.permission.MANAGE_MISSIONS
634
635**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
636
637**System API**: This is a system API and cannot be called by third-party applications.
638
639**Parameters**
640
641  | Name| Type| Mandatory| Description|
642  | -------- | -------- | -------- | -------- |
643  | missionId | number | Yes| Mission ID.|
644  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
645
646**Error codes**
647
648| ID| Error Message|
649| ------- | -------- |
650| 16300001 | Mission not found. |
651
652For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
653
654**Example**
655
656```ts
657import missionManager from '@ohos.app.ability.missionManager';
658
659let testMissionId = 2;
660try {
661    missionManager.lockMission(testMissionId, (err, data) => {
662        if (err) {
663            console.error('lockMission failed: ${err.message}');
664        } else {
665            console.info('lockMission successfully: ${JSON.stringify(data)}');
666        }
667    });
668} catch (err) {
669    console.error('lockMission failed: ${err.message}');
670}
671```
672
673## missionManager.lockMission
674
675lockMission(missionId: number): Promise&lt;void&gt;;
676
677Locks a given mission. This API uses a promise to return the result.
678
679**Required permissions**: ohos.permission.MANAGE_MISSIONS
680
681**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
682
683**System API**: This is a system API and cannot be called by third-party applications.
684
685**Parameters**
686
687  | Name| Type| Mandatory| Description|
688  | -------- | -------- | -------- | -------- |
689  | missionId | number | Yes| Mission ID.|
690
691**Return value**
692
693  | Type| Description|
694  | -------- | -------- |
695  | Promise&lt;void&gt; | Promise used to return the result.|
696
697**Error codes**
698
699| ID| Error Message|
700| ------- | -------- |
701| 16300001 | Mission not found. |
702
703For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
704
705**Example**
706```ts
707import missionManager from '@ohos.app.ability.missionManager';
708
709let testMissionId = 2;
710try {
711    missionManager.lockMission(testMissionId).then((data) => {
712        console.info('lockMission successfully. Data: ${JSON.stringify(data)}');
713    }).catch(error => {
714        console.error('lockMission failed. Cause: ${error.message}');
715    });
716} catch (error) {
717    console.error('lockMission failed. Cause: ${error.message}');
718}
719```
720
721## missionManager.unlockMission
722
723unlockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
724
725Unlocks a given mission. This API uses an asynchronous callback to return the result.
726
727**Required permissions**: ohos.permission.MANAGE_MISSIONS
728
729**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
730
731**System API**: This is a system API and cannot be called by third-party applications.
732
733**Parameters**
734
735| Name| Type| Mandatory| Description|
736| -------- | -------- | -------- | -------- |
737| missionId | number | Yes| Mission ID.|
738| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
739
740**Error codes**
741
742| ID| Error Message|
743| ------- | -------- |
744| 16300001 | Mission not found. |
745
746For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
747
748**Example**
749```ts
750import missionManager from '@ohos.app.ability.missionManager';
751
752let testMissionId = 2;
753try {
754    missionManager.unlockMission(testMissionId, (err, data) => {
755        if (err) {
756            console.error('unlockMission failed: ${err.message}');
757        } else {
758            console.info('unlockMission successfully: ${JSON.stringify(data)}');
759        }
760    });
761} catch (err) {
762    console.error('unlockMission failed: ${err.message}');
763}
764```
765
766## missionManager.unlockMission
767
768unlockMission(missionId: number): Promise&lt;void&gt;;
769
770Unlocks a given mission. This API uses a promise to return the result.
771
772**Required permissions**: ohos.permission.MANAGE_MISSIONS
773
774**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
775
776**System API**: This is a system API and cannot be called by third-party applications.
777
778**Parameters**
779
780  | Name| Type| Mandatory| Description|
781  | -------- | -------- | -------- | -------- |
782  | missionId | number | Yes| Mission ID.|
783
784**Return value**
785
786  | Type| Description|
787  | -------- | -------- |
788  | Promise&lt;void&gt; | Promise used to return the result.|
789
790**Error codes**
791
792| ID| Error Message|
793| ------- | -------- |
794| 16300001 | Mission not found. |
795
796For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
797
798**Example**
799
800```ts
801import missionManager from '@ohos.app.ability.missionManager';
802
803let testMissionId = 2;
804try {
805    missionManager.unlockMission(testMissionId).then((data) => {
806        console.info('unlockMission successfully. Data: ${JSON.stringify(data)}');
807    }).catch(error => {
808        console.error('unlockMission failed. Cause: ${error.message}');
809    });
810} catch (error) {
811    console.error('unlockMission failed. Cause: ${error.message}');
812}
813```
814
815## missionManager.clearMission
816
817clearMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
818
819Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result.
820
821**Required permissions**: ohos.permission.MANAGE_MISSIONS
822
823**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
824
825**System API**: This is a system API and cannot be called by third-party applications.
826
827**Parameters**
828
829  | Name| Type| Mandatory| Description|
830  | -------- | -------- | -------- | -------- |
831  | missionId | number | Yes| Mission ID.|
832  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
833
834**Example**
835
836```ts
837import missionManager from '@ohos.app.ability.missionManager';
838
839let testMissionId = 2;
840try {
841    missionManager.clearMission(testMissionId, (err, data) => {
842        if (err) {
843            console.error('clearMission failed: ${err.message}');
844        } else {
845            console.info('clearMission successfully: ${JSON.stringify(data)}');
846        }
847    });
848} catch (err) {
849    console.error('clearMission failed: ${err.message}');
850}
851```
852
853
854## missionManager.clearMission
855
856clearMission(missionId: number): Promise&lt;void&gt;;
857
858Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result.
859
860**Required permissions**: ohos.permission.MANAGE_MISSIONS
861
862**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
863
864**System API**: This is a system API and cannot be called by third-party applications.
865
866**Parameters**
867
868  | Name| Type| Mandatory| Description|
869  | -------- | -------- | -------- | -------- |
870  | missionId | number | Yes| Mission ID.|
871
872**Return value**
873
874  | Type| Description|
875  | -------- | -------- |
876  | Promise&lt;void&gt; | Promise used to return the result.|
877
878**Example**
879
880```ts
881import missionManager from '@ohos.app.ability.missionManager';
882
883let testMissionId = 2;
884try {
885    missionManager.clearMission(testMissionId).then((data) => {
886        console.info('clearMission successfully. Data: ${JSON.stringify(data)}');
887    }).catch(error => {
888        console.error('clearMission failed. Cause: ${error.message}');
889    });
890} catch (error) {
891    console.error('clearMission failed. Cause: ${error.message}');
892}
893```
894
895## missionManager.clearAllMissions
896
897clearAllMissions(callback: AsyncCallback&lt;void&gt;): void;
898
899Clears all unlocked missions. This API uses an asynchronous callback to return the result.
900
901**Required permissions**: ohos.permission.MANAGE_MISSIONS
902
903**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
904
905**System API**: This is a system API and cannot be called by third-party applications.
906
907**Example**
908
909```ts
910import missionManager from '@ohos.app.ability.missionManager';
911
912try {
913    missionManager.clearAllMissions(err => {
914        if (err) {
915            console.error('clearAllMissions failed: ${err.message}');
916        } else {
917            console.info('clearAllMissions successfully.');
918        }
919    });
920} catch (err) {
921    console.error('clearAllMissions failed: ${err.message}');
922}
923```
924
925## missionManager.clearAllMissions
926
927clearAllMissions(): Promise&lt;void&gt;;
928
929Clears all unlocked missions. This API uses a promise to return the result.
930
931**Required permissions**: ohos.permission.MANAGE_MISSIONS
932
933**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
934
935**System API**: This is a system API and cannot be called by third-party applications.
936
937**Return value**
938
939  | Type| Description|
940  | -------- | -------- |
941  | Promise&lt;void&gt; | Promise used to return the result.|
942
943**Example**
944
945```ts
946import missionManager from '@ohos.app.ability.missionManager';
947
948try {
949    missionManager.clearAllMissions(bundleName).then((data) => {
950        console.info('clearAllMissions successfully. Data: ${JSON.stringify(data)}');
951    }).catch(err => {
952        console.error('clearAllMissions failed: ${err.message}');
953    });
954} catch (err) {
955    console.error('clearAllMissions failed: ${err.message}');
956}
957```
958
959## missionManager.moveMissionToFront
960
961moveMissionToFront(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
962
963Switches a given mission to the foreground. This API uses an asynchronous callback to return the result.
964
965**Required permissions**: ohos.permission.MANAGE_MISSIONS
966
967**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
968
969**System API**: This is a system API and cannot be called by third-party applications.
970
971**Parameters**
972
973  | Name| Type| Mandatory| Description|
974  | -------- | -------- | -------- | -------- |
975  | missionId | number | Yes| Mission ID.|
976  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
977
978**Error codes**
979
980| ID| Error Message|
981| ------- | -------- |
982| 16000009 | An ability cannot be started or stopped in Wukong mode. |
983
984For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
985
986**Example**
987
988```ts
989import missionManager from '@ohos.app.ability.missionManager';
990
991let testMissionId = 2;
992try {
993    missionManager.moveMissionToFront(testMissionId, (err, data) => {
994        if (err) {
995            console.error('moveMissionToFront failed: ${err.message}');
996        } else {
997            console.info('moveMissionToFront successfully: ${JSON.stringify(data)}');
998        }
999    });
1000} catch (err) {
1001    console.error('moveMissionToFront failed: ${err.message}');
1002}
1003```
1004
1005## missionManager.moveMissionToFront
1006
1007moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void;
1008
1009Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result.
1010
1011**Required permissions**: ohos.permission.MANAGE_MISSIONS
1012
1013**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
1014
1015**System API**: This is a system API and cannot be called by third-party applications.
1016
1017**Parameters**
1018
1019  | Name| Type| Mandatory| Description|
1020  | -------- | -------- | -------- | -------- |
1021  | missionId | number | Yes| Mission ID.|
1022  | 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.|
1023  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
1024
1025**Error codes**
1026
1027| ID| Error Message|
1028| ------- | -------- |
1029| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1030
1031For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
1032
1033**Example**
1034
1035```ts
1036import missionManager from '@ohos.app.ability.missionManager';
1037
1038let testMissionId = 2;
1039try {
1040    missionManager.moveMissionToFront(testMissionId, {windowMode : 101}, (err, data) => {
1041        if (err) {
1042            console.error('moveMissionToFront failed: ${err.message}');
1043        } else {
1044            console.info('moveMissionToFront successfully: ${JSON.stringify(data)}');
1045        }
1046    });
1047} catch (err) {
1048    console.error('moveMissionToFront failed: ${err.message}');
1049}
1050```
1051
1052## missionManager.moveMissionToFront
1053
1054moveMissionToFront(missionId: number, options?: StartOptions): Promise&lt;void&gt;;
1055
1056Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result.
1057
1058**Required permissions**: ohos.permission.MANAGE_MISSIONS
1059
1060**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
1061
1062**System API**: This is a system API and cannot be called by third-party applications.
1063
1064**Parameters**
1065
1066  | Name| Type| Mandatory| Description|
1067  | -------- | -------- | -------- | -------- |
1068  | missionId | number | Yes| Mission ID.|
1069  | 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.|
1070
1071**Return value**
1072
1073  | Type| Description|
1074  | -------- | -------- |
1075  | Promise&lt;void&gt; | Promise used to return the result.|
1076
1077**Error codes**
1078
1079| ID| Error Message|
1080| ------- | -------- |
1081| 16000009 | An ability cannot be started or stopped in Wukong mode. |
1082
1083For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md).
1084
1085**Example**
1086
1087```ts
1088import missionManager from '@ohos.app.ability.missionManager';
1089
1090let testMissionId = 2;
1091try {
1092    missionManager.moveMissionToFront(testMissionId).then((data) => {
1093        console.info('moveMissionToFront successfully. Data: ${JSON.stringify(data)}');
1094    }).catch(error => {
1095        console.error('moveMissionToFront failed. Cause: ${error.message}');
1096    });
1097} catch (error) {
1098    console.error('moveMissionToFront failed. Cause: ${error.message}');
1099}
1100```
1101