js-apis-missionManager.md 22.0 KB
Newer Older
W
wusongqing 已提交
1 2 3
# missionManager


W
wusongqing 已提交
4
> **NOTE**<br/>
W
wusongqing 已提交
5
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
6

W
wusongqing 已提交
7
missionManager provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
W
wusongqing 已提交
8 9 10 11 12 13 14

## Modules to Import

```
import missionManager from '@ohos.application.missionManager'
```

W
wusongqing 已提交
15 16 17
## Required Permissions

ohos.permission.MANAGE_MISSIONS
W
wusongqing 已提交
18 19 20

## missionManager.registerMissionListener

W
wusongqing 已提交
21
registerMissionListener(listener: MissionListener): number;
W
wusongqing 已提交
22 23 24 25 26 27 28

Registers a listener to observe the mission status.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
29 30 31
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| listener | MissionListener | Yes| Listener to register.|
W
wusongqing 已提交
32 33 34

**Return value**

W
wusongqing 已提交
35 36 37
| Type| Description|
| -------- | -------- |
| number | Returns the unique index of the mission status listener, which is created by the system and allocated when the listener is registered.|
W
wusongqing 已提交
38 39 40 41 42

**Example**

  ```js
  var listener =  {
W
wusongqing 已提交
43 44 45 46 47
  	onMissionCreated: function(mission){"--------onMissionCreated-------"},
  	onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
  	onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
  	onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
  	onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
W
wusongqing 已提交
48 49 50 51 52 53 54 55 56
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

  ```


## missionManager.unregisterMissionListener

W
wusongqing 已提交
57
unregisterMissionListener(listenerId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
58

W
wusongqing 已提交
59
Deregisters a mission status listener. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
60 61 62 63 64

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
65 66 67 68
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
69 70 71 72 73

**Example**

  ```js
  var listener =  {
W
wusongqing 已提交
74 75 76 77 78
  	onMissionCreated: function(mission){"--------onMissionCreated-------"},
  	onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
  	onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
  	onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
  	onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
W
wusongqing 已提交
79 80 81 82 83 84 85 86 87 88 89 90
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

  missionManager.unregisterMissionListener(listenerid, (error) => {
    console.log("unregisterMissionListener");
  })
  ```


## missionManager.unregisterMissionListener

W
wusongqing 已提交
91
unregisterMissionListener(listenerId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
92

W
wusongqing 已提交
93
Deregisters a mission status listener. This API uses a promise to return the result.
W
wusongqing 已提交
94 95 96 97 98

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
99 100 101
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
W
wusongqing 已提交
102

W
wusongqing 已提交
103 104
**Return value**

W
wusongqing 已提交
105 106 107
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
108

W
wusongqing 已提交
109 110 111 112
**Example**

  ```js
  var listener =  {
W
wusongqing 已提交
113 114 115 116 117 118 119 120 121 122 123 124
      onMissionCreated: function(mission){"--------onMissionCreated-------"},
      onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
      onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
      onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
      onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
      };
      console.log("registerMissionListener")
      var listenerid = missionManager.registerMissionListener(listener);

      missionManager.unregisterMissionListener(listenerid).catch(function (err){
        console.log(err);
      });
W
wusongqing 已提交
125 126 127 128 129
  ```


## missionManager.getMissionInfo

W
wusongqing 已提交
130
getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;MissionInfo&gt;): void;
W
wusongqing 已提交
131

W
wusongqing 已提交
132
Obtains the information about a given mission. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
133 134 135 136 137

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
138 139 140 141 142
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;[MissionInfo](#missioninfo)&gt; | Yes| Callback used to return the mission information obtained.|
W
wusongqing 已提交
143 144 145 146 147 148

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
149 150 151 152 153 154 155 156 157 158
  var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
      missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
        console.log("getMissionInfo is called, error.code = " + error.code)
        console.log("mission.missionId = " + mission.missionId);
        console.log("mission.runningState = " + mission.runningState);
        console.log("mission.lockedState = " + mission.lockedState);
        console.log("mission.timestamp = " + mission.timestamp);
        console.log("mission.label = " + mission.label);
        console.log("mission.iconPath = " + mission.iconPath);
      });
W
wusongqing 已提交
159 160 161 162 163
  ```


## missionManager.getMissionInfo

W
wusongqing 已提交
164
getMissionInfo(deviceId: string, missionId: number): Promise&lt;MissionInfo&gt;;
W
wusongqing 已提交
165

W
wusongqing 已提交
166
Obtains the information about a given mission. This API uses a promise to return the result.
W
wusongqing 已提交
167 168 169 170 171

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
172 173 174 175
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
176 177 178

**Return value**

W
wusongqing 已提交
179 180 181
| Type| Description|
| -------- | -------- |
| Promise&lt;[MissionInfo](#missioninfo)&gt; | Promise used to return the mission information obtained.|
W
wusongqing 已提交
182 183 184 185 186 187

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
188
  var mission = missionManager.getMissionInfo("", 10).catch(function (err){
W
wusongqing 已提交
189 190 191 192 193 194 195
      console.log(err);
  });
  ```


## missionManager.getMissionInfos

W
wusongqing 已提交
196
getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback&lt;Array&lt;MissionInfo&gt;&gt;): void;
W
wusongqing 已提交
197

W
wusongqing 已提交
198
Obtains information about all missions. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
199 200 201 202 203

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
204 205 206 207 208
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| numMax | number | Yes| Maximum number of missions whose information can be obtained.|
| callback | AsyncCallback&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Yes| Callback used to return the array of mission information obtained.|
W
wusongqing 已提交
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
      console.log("getMissionInfos is called, error.code = " + error.code);
      console.log("size = " + missions.length);
      console.log("missions = " + JSON.stringify(missions));
  })
  ```


## missionManager.getMissionInfos

W
wusongqing 已提交
225
getMissionInfos(deviceId: string, numMax: number): Promise&lt;Array&lt;MissionInfo&gt;&gt;;
W
wusongqing 已提交
226

W
wusongqing 已提交
227
Obtains information about all missions. This API uses a promise to return the result.
W
wusongqing 已提交
228 229 230 231 232

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
233 234 235 236
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| numMax | number | Yes| Maximum number of missions whose information can be obtained.|
W
wusongqing 已提交
237 238 239

**Return value**

W
wusongqing 已提交
240 241 242
| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[MissionInfo](#missioninfo)&gt;&gt; | Promise used to return the array of mission information obtained.|
W
wusongqing 已提交
243 244 245 246 247 248

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
249
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
250 251 252 253 254 255 256
      console.log(err);
  });
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
257
getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback&lt;MissionSnapshot&gt;): void;
W
wusongqing 已提交
258 259 260 261 262 263 264

Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
265 266 267 268 269
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|
W
wusongqing 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.getMissionSnapShot("", id, (error, snapshot) => {
  	console.log("getMissionSnapShot is called, error.code = " + error.code);
  	console.log("bundleName = " + snapshot.ability.bundleName);
  })
  })
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
292
getMissionSnapShot(deviceId: string, missionId: number): Promise&lt;MissionSnapshot&gt;;
W
wusongqing 已提交
293 294 295 296 297 298 299

Obtains the snapshot of a given mission. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
300 301 302 303
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
304 305 306

**Return value**

W
wusongqing 已提交
307 308 309
| Type| Description|
| -------- | -------- |
| Promise&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|
W
wusongqing 已提交
310 311 312 313 314 315

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
316 317 318 319 320 321 322 323 324 325 326
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
    }).catch(function(err){console.log(err);});
    console.log("size = " + allMissions.length);
    console.log("missions = " + JSON.stringify(allMissions));
    var id = allMissions[0].missionId;

    var snapshot = missionManager.getMissionSnapShot("", id).catch(function (err){
        console.log(err);
    });
W
wusongqing 已提交
327 328 329 330 331
  ```


## missionManager.lockMission

W
wusongqing 已提交
332
lockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
333 334 335 336 337 338 339

Locks a given mission. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
340 341 342 343
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.lockMission(id).then(() => {
  	console.log("lockMission is called ");
  });
  });
  ```


## missionManager.lockMission

W
wusongqing 已提交
365
lockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
366 367 368 369 370 371 372

Locks a given mission. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
373 374 375
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
376

W
wusongqing 已提交
377 378
**Return value**

W
wusongqing 已提交
379 380 381
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
382

W
wusongqing 已提交
383 384 385 386
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'
W
wusongqing 已提交
387 388 389 390
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
391 392 393 394
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
395
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
396 397 398 399 400 401 402
      console.log(err);
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
403
unlockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
404 405 406 407 408 409 410

Unlocks a given mission. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
411 412 413 414
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.unlockMission(id).then(() => {
  	console.log("unlockMission is called ");
  });
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
436
unlockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
437 438 439 440 441 442 443

Unlocks a given mission. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
444 445 446
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
447

W
wusongqing 已提交
448 449
**Return value**

W
wusongqing 已提交
450 451 452
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
453

W
wusongqing 已提交
454 455 456 457 458
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
459 460 461 462
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
463 464 465 466
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
467
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
468 469
      console.log(err);
  });
W
wusongqing 已提交
470
  missionManager.unlockMission(id).catch(function (err){
W
wusongqing 已提交
471 472 473 474 475 476 477
      console.log(err);
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
478
clearMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
479 480 481 482 483 484 485

Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
486 487 488 489
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.clearMission(id).then(() => {
  	console.log("clearMission is called ");
  });
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
511
clearMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
512 513 514 515 516 517 518

Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
519 520 521
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
522

W
wusongqing 已提交
523 524
**Return value**

W
wusongqing 已提交
525 526 527
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
528

W
wusongqing 已提交
529 530 531 532 533
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
534 535 536 537
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
538 539 540 541
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
542
  missionManager.clearMission(id).catch(function (err){
W
wusongqing 已提交
543 544 545 546 547 548 549
    console.log(err);
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
550
clearAllMissions(callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568

Clears all unlocked missions. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.clearAllMissions().then(() => {
    console.log("clearAllMissions is called ");
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
569
clearAllMissions(): Promise&lt;void&gt;;
W
wusongqing 已提交
570 571 572 573 574

Clears all unlocked missions. This API uses a promise to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

W
wusongqing 已提交
575 576
**Return value**

W
wusongqing 已提交
577 578 579
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
580

W
wusongqing 已提交
581 582 583 584
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'
W
wusongqing 已提交
585
  missionManager.clearAllMissions().catch(function (err){
W
wusongqing 已提交
586 587 588 589 590 591 592
    console.log(err);
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
593
moveMissionToFront(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
594 595 596 597 598 599 600

Switches a given mission to the foreground. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
601 602 603 604
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.moveMissionToFront(id).then(() => {
  	console.log("moveMissionToFront is called ");
  });
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
626
moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
627

W
wusongqing 已提交
628
Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
629 630 631 632 633

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
634 635 636 637 638
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| options | StartOptions | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
  	console.log("moveMissionToFront is called ");
    });
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
660
moveMissionToFront(missionId: number, options?: StartOptions): Promise&lt;void&gt;;
W
wusongqing 已提交
661

W
wusongqing 已提交
662
Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result.
W
wusongqing 已提交
663 664 665 666 667

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**Parameters**

W
wusongqing 已提交
668 669 670 671
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| options | StartOptions | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
W
wusongqing 已提交
672

W
wusongqing 已提交
673 674
**Return value**

W
wusongqing 已提交
675 676 677
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
678

W
wusongqing 已提交
679 680 681 682 683
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
684 685 686 687
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
688 689 690 691
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
692
  missionManager.moveMissionToFront(id).catch(function (err){
W
wusongqing 已提交
693 694 695
    console.log(err);
  });
  ```
W
wusongqing 已提交
696 697 698 699 700 701 702

## MissionInfo

Describes the mission information.

**System capability**: SystemCapability.Ability.AbilityBase

W
wusongqing 已提交
703
| Name| Type| Readable| Writable| Description|
W
wusongqing 已提交
704
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
705 706 707 708 709 710 711 712
| missionId | number | Yes| Yes| Mission ID.|
| runningState | number | Yes| Yes| Running state of the mission.|
| lockedState | boolean | Yes| Yes| Locked state of the mission.|
| timestamp | string | Yes| Yes| Latest time when the mission was created or updated.|
| want | [Want](js-apis-application-Want.md) | Yes| Yes| **Want** information of the mission.|
| label | string | Yes| Yes| Label of the mission.|
| iconPath | string | Yes| Yes| Path of the mission icon.|
| continuable | boolean | Yes| Yes| Whether the mission can be continued on another device. |