js-apis-missionManager.md 22.2 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 29 30 31 32 33 34 35 36

Registers a listener to observe the mission status.

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | listener | MissionListener | Yes| Listener to register.|

**Return value**

  | Type| Description|
  | -------- | -------- |
W
wusongqing 已提交
37
  | 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 65 66

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

**Parameters**

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

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

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

**Parameters**

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

W
wusongqing 已提交
103 104 105 106 107 108
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 138 139 140 141

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

**Parameters**

  | 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 已提交
142
  | 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 172 173 174 175 176 177 178 179 180

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

**Parameters**

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

**Return value**

  | Type| Description|
  | -------- | -------- |
W
wusongqing 已提交
181
  | 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 204 205 206 207

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

**Parameters**

  | 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 已提交
208
  | 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 233 234 235 236 237 238 239 240 241

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

**Parameters**

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

**Return value**

  | Type| Description|
  | -------- | -------- |
W
wusongqing 已提交
242
  | 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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

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

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

**Parameters**

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

**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 300 301 302 303 304 305 306 307 308

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

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

**Parameters**

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

**Return value**

  | Type| Description|
  | -------- | -------- |
W
wusongqing 已提交
309
  | 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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|

**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 373 374 375 376

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|

W
wusongqing 已提交
377 378 379 380 381 382
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 444 445 446 447

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|

W
wusongqing 已提交
448 449 450 451 452 453
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

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

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|

**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 519 520 521 522

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

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|

W
wusongqing 已提交
523 524 525 526 527 528
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 577 578 579 580
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

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

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

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|

**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 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659

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

**Parameters**

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

**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 668 669 670 671 672

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

**Parameters**

  | 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 已提交
673 674 675 676 677 678
**Return value**

  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 

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 703 704 705 706 707 708

## MissionInfo

Describes the mission information.

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

| Name| Type| Readable| Writable| Description| 
| -------- | -------- | -------- | -------- | -------- |
| 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.| 
W
wusongqing 已提交
709
| want | [Want](js-apis-application-Want.md) | Yes| Yes| **Want** information of the mission.| 
W
wusongqing 已提交
710 711 712
| label | string | Yes| Yes| Label of the mission.| 
| iconPath | string | Yes| Yes| Path of the mission icon.| 
| continuable | boolean | Yes| Yes| Whether the mission is continuable.|