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


W
wusongqing 已提交
4 5
> **NOTE**
>
Z
zengyawen 已提交
6
> 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 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21


Provides mission management. You can use the APIs to lock, unlock, and clear missions, and switch a mission to the foreground.


## Modules to Import


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


## missionManager.registerMissionListener

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

Registers a listener to observe the mission status.

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

**Parameters**

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

**Return value**

W
wusongqing 已提交
36 37 38
| 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 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

**Example**

  ```js
  var listener =  {
  	onMissionCreated: this.onMissionCreatedCallback,
  	onMissionDestroyed: this.onMissionDestroyedCallback,
  	onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
  	onMissionMovedToFront: this.onMissionMovedToFrontCallback
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

  ```


## missionManager.unregisterMissionListener

Z
zengyawen 已提交
57
unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>): 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<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

**Example**

  ```js
  var listener =  {
    onMissionCreated: this.onMissionCreatedCallback,
    onMissionDestroyed: this.onMissionDestroyedCallback,
    onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
    onMissionMovedToFront: this.onMissionMovedToFrontCallback
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

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


## missionManager.unregisterMissionListener

Z
zengyawen 已提交
90
unregisterMissionListener(listenerId: number): Promise<void>;
W
wusongqing 已提交
91

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

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

**Parameters**

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

Z
zengyawen 已提交
102 103
**Return value**

W
wusongqing 已提交
104 105 106
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
107

W
wusongqing 已提交
108 109 110 111 112 113 114 115 116 117 118 119
**Example**

  ```js
  var listener =  {
      onMissionCreated: this.onMissionCreatedCallback,
      onMissionDestroyed: this.onMissionDestroyedCallback,
      onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
      onMissionMovedToFront: this.onMissionMovedToFrontCallback
    };
    console.log("registerMissionListener")
    var listenerid = missionManager.registerMissionListener(listener);

Z
zengyawen 已提交
120
    missionManager.unregisterMissionListener(listenerid).catch(function (err){
W
wusongqing 已提交
121 122 123 124 125 126 127
      console.log(err);
    });
  ```


## missionManager.getMissionInfo

Z
zengyawen 已提交
128
getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void;
W
wusongqing 已提交
129

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

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

**Parameters**

W
wusongqing 已提交
136 137 138 139 140
| 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<[MissionInfo](#missioninfo)> | Yes| Callback used to return the mission information obtained.|
W
wusongqing 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154

**Example**

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

  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);
Z
zengyawen 已提交
155
  });
W
wusongqing 已提交
156 157 158 159 160
  ```


## missionManager.getMissionInfo

Z
zengyawen 已提交
161
getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>;
W
wusongqing 已提交
162

W
wusongqing 已提交
163
Obtains the information about a given mission. This API uses a promise to return the result.
W
wusongqing 已提交
164 165 166 167 168

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

**Parameters**

W
wusongqing 已提交
169 170 171 172
| 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 已提交
173 174 175

**Return value**

W
wusongqing 已提交
176 177 178
| Type| Description|
| -------- | -------- |
| Promise<[MissionInfo](#missioninfo)> | Promise used to return the mission information obtained.|
W
wusongqing 已提交
179 180 181 182 183 184

**Example**

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

Z
zengyawen 已提交
185
  var mission = missionManager.getMissionInfo("", id).catch(function (err){
W
wusongqing 已提交
186 187 188 189 190 191 192
      console.log(err);
  });
  ```


## missionManager.getMissionInfos

Z
zengyawen 已提交
193
getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void;
W
wusongqing 已提交
194

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

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

**Parameters**

W
wusongqing 已提交
201 202 203 204 205
| 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<Array<[MissionInfo](#missioninfo)>> | Yes| Callback used to return the array of mission information obtained.|
W
wusongqing 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

**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

Z
zengyawen 已提交
222
getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>;
W
wusongqing 已提交
223

W
wusongqing 已提交
224
Obtains information about all missions. This API uses a promise to return the result.
W
wusongqing 已提交
225 226 227 228 229

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

**Parameters**

W
wusongqing 已提交
230 231 232 233
| 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 已提交
234 235 236

**Return value**

W
wusongqing 已提交
237 238 239
| Type| Description|
| -------- | -------- |
| Promise<Array<[MissionInfo](#missioninfo)>> | Promise used to return the array of mission information obtained.|
W
wusongqing 已提交
240 241 242 243 244 245

**Example**

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

Z
zengyawen 已提交
246
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
247 248 249 250 251 252 253
      console.log(err);
  });
  ```


## missionManager.getMissionSnapShot

Z
zengyawen 已提交
254
getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void;
W
wusongqing 已提交
255 256 257 258 259 260 261

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 已提交
262 263 264 265 266
| 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<[MissionSnapshot](js-apis-application-MissionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
W
wusongqing 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

**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

Z
zengyawen 已提交
289
getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>;
W
wusongqing 已提交
290 291 292 293 294 295 296

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 已提交
297 298 299 300
| 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 已提交
301 302 303

**Return value**

W
wusongqing 已提交
304 305 306
| Type| Description|
| -------- | -------- |
| Promise<[MissionSnapshot](js-apis-application-MissionSnapshot.md)> | Promise used to return the snapshot information obtained.|
W
wusongqing 已提交
307 308 309 310 311 312

**Example**

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

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


## missionManager.lockMission

Z
zengyawen 已提交
327
lockMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
328 329 330 331 332 333 334

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

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

**Parameters**

W
wusongqing 已提交
335 336 337 338
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359

**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

Z
zengyawen 已提交
360
lockMission(missionId: number): Promise<void>;
W
wusongqing 已提交
361 362 363 364 365 366 367

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

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

**Parameters**

W
wusongqing 已提交
368 369 370
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
371

Z
zengyawen 已提交
372 373
**Return value**

W
wusongqing 已提交
374 375 376
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
377

W
wusongqing 已提交
378 379 380 381 382
**Example**

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

Z
zengyawen 已提交
383
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
384 385 386 387 388 389
    console.log(err);
  });
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

Z
zengyawen 已提交
390
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
391 392 393 394 395 396 397
      console.log(err);
  });
  ```


## missionManager.unlockMission

Z
zengyawen 已提交
398
unlockMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
399 400 401 402 403 404 405

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

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

**Parameters**

Z
zengyawen 已提交
406 407 408 409
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430

**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

Z
zengyawen 已提交
431
unlockMission(missionId: number): Promise<void>;
W
wusongqing 已提交
432 433 434 435 436 437 438

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

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

**Parameters**

W
wusongqing 已提交
439 440 441
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
442

Z
zengyawen 已提交
443 444
**Return value**

W
wusongqing 已提交
445 446 447
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
448

W
wusongqing 已提交
449 450 451 452 453
**Example**

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

Z
zengyawen 已提交
454
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
455 456 457 458 459 460
    console.log(err);
  });
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

Z
zengyawen 已提交
461
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
462 463
      console.log(err);
  });
Z
zengyawen 已提交
464
  missionManager.unlockMission(id).catch(function (err){
W
wusongqing 已提交
465 466 467 468 469 470 471
      console.log(err);
  });
  ```


## missionManager.clearMission

Z
zengyawen 已提交
472
clearMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
473 474 475 476 477 478 479

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 已提交
480 481 482 483
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504

**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

Z
zengyawen 已提交
505
clearMission(missionId: number): Promise<void>;
W
wusongqing 已提交
506 507 508 509 510 511 512

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 已提交
513 514 515
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
516

Z
zengyawen 已提交
517 518
**Return value**

W
wusongqing 已提交
519 520 521
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
522

W
wusongqing 已提交
523 524 525 526 527
**Example**

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

Z
zengyawen 已提交
528
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
529 530 531 532 533 534
    console.log(err);
  });
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

Z
zengyawen 已提交
535
  missionManager.clearMission(id).catch(function (err){
W
wusongqing 已提交
536 537 538 539 540 541 542
    console.log(err);
  });
  ```


## missionManager.clearAllMissions

Z
zengyawen 已提交
543
clearAllMissions(callback: AsyncCallback<void>): void;
W
wusongqing 已提交
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

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

Z
zengyawen 已提交
562
clearAllMissions(): Promise<void>;
W
wusongqing 已提交
563 564 565 566 567

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

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

Z
zengyawen 已提交
568 569
**Return value**

W
wusongqing 已提交
570 571 572
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
573

W
wusongqing 已提交
574 575 576 577
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'
Z
zengyawen 已提交
578
  missionManager.clearAllMissions().catch(function (err){
W
wusongqing 已提交
579 580 581 582 583 584 585
    console.log(err);
  });
  ```


## missionManager.moveMissionToFront

Z
zengyawen 已提交
586
moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
587 588 589 590 591 592 593

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 已提交
594 595 596 597
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618

**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

Z
zengyawen 已提交
619
moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
620 621 622 623 624 625 626

Switches a given mission to the foreground, with the startup parameters for the switch specified, such as the window mode and device ID. This API uses an asynchronous callback to return the result.

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

**Parameters**

W
wusongqing 已提交
627 628 629 630 631
| 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<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652

**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

Z
zengyawen 已提交
653
moveMissionToFront(missionId: number, options?: StartOptions): Promise<void>;
W
wusongqing 已提交
654

Z
zengyawen 已提交
655
Switches a given mission to the foreground, with the startup parameters for the switch specified, such as the window mode and device ID. This API uses a promise to return the result.
W
wusongqing 已提交
656 657 658 659 660

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

**Parameters**

W
wusongqing 已提交
661 662 663 664
| 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 已提交
665

Z
zengyawen 已提交
666 667
**Return value**

W
wusongqing 已提交
668 669 670
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the result.|
Z
zengyawen 已提交
671

W
wusongqing 已提交
672 673 674 675 676
**Example**

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

Z
zengyawen 已提交
677
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
678 679 680 681 682 683
    console.log(err);
  });
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

Z
zengyawen 已提交
684
  missionManager.moveMissionToFront(id).catch(function (err){
W
wusongqing 已提交
685 686 687
    console.log(err);
  });
  ```