1# MissionListener (System API)
2
3The MissionListener module defines the listeners used to observe the mission status. The listeners can be registered by using [on](js-apis-app-ability-missionManager-sys.md#missionmanageronmission).
4
5> **NOTE**
6>
7> 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.
8> The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import { missionManager } from '@kit.AbilityKit';
14```
15
16## Attributes
17
18**System API**: This is a system API and cannot be called by third-party applications.
19
20**System capability**: SystemCapability.Ability.AbilityRuntime.Mission
21
22| Name       | Type                | Mandatory| Description                                                        |
23| ----------- | -------- | ---- | ------------------------------------------------------------ |
24| onMissionCreated    | function               | No  | Called when the system creates a mission.                               |
25| onMissionDestroyed   | function               | No  | Called when the system destroys the mission.|
26| onMissionSnapshotChanged   | function               | No  | Called when the system updates the mission snapshot.|
27| onMissionMovedToFront   | function               | No  | Called when the system moves the mission to the foreground.|
28| onMissionLabelUpdated<sup>9+</sup>   | function               | No  | Called when the system updates the mission label.|
29| onMissionIconUpdated<sup>9+</sup>   | function               | No  | Called when the system updates the mission icon.|
30| onMissionClosed<sup>9+</sup>   | function               | No  | Called when the system closes the mission.|
31
32**Example**
33```ts
34import { missionManager } from '@kit.AbilityKit';
35import { BusinessError } from '@kit.BasicServicesKit';
36
37let listener: missionManager.MissionListener = {
38  onMissionCreated: (mission) => {
39    console.log(`onMissionCreated mission: ${JSON.stringify(mission)}`);
40  },
41  onMissionDestroyed: (mission) => {
42    console.log(`onMissionDestroyed mission: ${JSON.stringify(mission)}`);
43  },
44  onMissionSnapshotChanged: (mission) => {
45    console.log(`onMissionSnapshotChanged mission: ${JSON.stringify(mission)}`);
46  },
47  onMissionMovedToFront: (mission) => {
48    console.log(`onMissionMovedToFront mission: ${JSON.stringify(mission)}`);
49  },
50  onMissionLabelUpdated: (mission) => {
51    console.log(`onMissionLabelUpdated mission: ${JSON.stringify(mission)}`);
52  },
53  onMissionIconUpdated: (mission, icon) => {
54    console.log(`onMissionIconUpdated mission: ${JSON.stringify(mission)}`);
55    console.log(`onMissionIconUpdated icon: ${JSON.stringify(icon)}`);
56  },
57  onMissionClosed: (mission) => {
58    console.log(`onMissionClosed mission: ${JSON.stringify(mission)}`);
59  }
60};
61
62try {
63  let listenerId = missionManager.on('mission', listener);
64} catch (paramError) {
65  console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`);
66}
67```
68