1# MissionListener (System API) 2 3The 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## MissionListener 17 18### onMissionCreated 19 20onMissionCreated(mission: number): void 21 22Called when the system creates a mission. 23 24**System API**: This is a system API. 25 26**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 27 28**Parameters** 29 30| Name| Type| Mandatory| Description| 31| -------- | -------- | -------- | -------- | 32| mission | number | Yes| Mission ID.| 33 34**Example** 35 36For details, see [onMissionClosed](#onmissionclosed9). 37 38### onMissionDestroyed 39 40onMissionDestroyed(mission: number): void 41 42Called when the system destroys a mission. 43 44**System API**: This is a system API. 45 46**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 47 48**Parameters** 49 50| Name| Type| Mandatory| Description| 51| -------- | -------- | -------- | -------- | 52| mission | number | Yes| Mission ID.| 53 54**Example** 55 56For details, see [onMissionClosed](#onmissionclosed9). 57 58### onMissionSnapshotChanged 59 60onMissionSnapshotChanged(mission: number): void 61 62Called when the system updates the snapshot of a mission. 63 64**System API**: This is a system API. 65 66**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 67 68**Parameters** 69 70| Name| Type| Mandatory| Description| 71| -------- | -------- | -------- | -------- | 72| mission | number | Yes| Mission ID.| 73 74**Example** 75 76For details, see [onMissionClosed](#onmissionclosed9). 77 78### onMissionMovedToFront 79 80onMissionMovedToFront(mission: number): void 81 82Called when the system moves a mission to the foreground. 83 84**System API**: This is a system API. 85 86**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 87 88**Parameters** 89 90| Name| Type| Mandatory| Description| 91| -------- | -------- | -------- | -------- | 92| mission | number | Yes| Mission ID.| 93 94**Example** 95 96For details, see [onMissionClosed](#onmissionclosed9). 97 98### onMissionLabelUpdated<sup>9+</sup> 99 100onMissionLabelUpdated(mission: number): void 101 102Called when the system updates the label of a mission. 103 104**System API**: This is a system API. 105 106**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 107 108**Parameters** 109 110| Name| Type| Mandatory| Description| 111| -------- | -------- | -------- | -------- | 112| mission | number | Yes| Mission ID.| 113 114**Example** 115 116For details, see [onMissionClosed](#onmissionclosed9). 117 118### onMissionIconUpdated<sup>9+</sup> 119 120onMissionIconUpdated(mission: number, icon: image.PixelMap): void 121 122Called when the system updates the icon of a mission. 123 124**System API**: This is a system API. 125 126**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 127 128**Parameters** 129 130| Name| Type| Mandatory| Description| 131| -------- | -------- | -------- | -------- | 132| mission | number | Yes| Mission ID.| 133| icon | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes| New mission icon.| 134 135**Example** 136 137For details, see [onMissionClosed](#onmissionclosed9). 138 139### onMissionClosed<sup>9+</sup> 140 141onMissionClosed(mission: number): void 142 143Called when the system closes a mission. 144 145**System API**: This is a system API. 146 147**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 148 149**Parameters** 150 151| Name| Type| Mandatory| Description| 152| -------- | -------- | -------- | -------- | 153| mission | number | Yes| Mission ID.| 154 155**Example** 156```ts 157import { missionManager } from '@kit.AbilityKit'; 158import { BusinessError } from '@kit.BasicServicesKit'; 159 160let listener: missionManager.MissionListener = { 161 onMissionCreated: (mission) => { 162 console.log(`onMissionCreated mission: ${JSON.stringify(mission)}`); 163 }, 164 onMissionDestroyed: (mission) => { 165 console.log(`onMissionDestroyed mission: ${JSON.stringify(mission)}`); 166 }, 167 onMissionSnapshotChanged: (mission) => { 168 console.log(`onMissionSnapshotChanged mission: ${JSON.stringify(mission)}`); 169 }, 170 onMissionMovedToFront: (mission) => { 171 console.log(`onMissionMovedToFront mission: ${JSON.stringify(mission)}`); 172 }, 173 onMissionLabelUpdated: (mission) => { 174 console.log(`onMissionLabelUpdated mission: ${JSON.stringify(mission)}`); 175 }, 176 onMissionIconUpdated: (mission, icon) => { 177 console.log(`onMissionIconUpdated mission: ${JSON.stringify(mission)}`); 178 console.log(`onMissionIconUpdated icon: ${JSON.stringify(icon)}`); 179 }, 180 onMissionClosed: (mission) => { 181 console.log(`onMissionClosed mission: ${JSON.stringify(mission)}`); 182 } 183}; 184 185try { 186 let listenerId = missionManager.on('mission', listener); 187} catch (paramError) { 188 console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); 189} 190``` 191