• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Mission Management Scenarios
2
3
4Before getting started with the development of mission management, be familiar with the following concepts related to mission management:
5
6
7- AbilityRecord: minimum unit for the system service to manage a UIAbility instance. It corresponds to a UIAbility component instance of an application. A maximum of 512 UIAbility instances can be managed on the system service side.
8
9- MissionRecord: minimum unit for mission management. One MissionRecord has only one AbilityRecord. In other words, a UIAbility component instance corresponds to a mission.
10
11- MissionList: a list of missions started from the home screen. It records the startup relationship between missions. In a MissionList, an above mission is started by the mission under it, and the mission at the bottom is started by the home screen.
12
13- MissionListManager: system mission management module that maintains all the MissionLists and is consistent with the list in **Recents**.
14
15  **Figure 1** Mission management
16  ![mission-list-manager](figures/mission-list-manager.png)
17
18
19Missions are managed by system applications (such as home screen), rather than third-party applications. Users interact with missions through **Recents**. After creating a mission, users can perform the following operations on **Recents**:
20
21
22- Delete a mission.
23
24- Lock or unlock a mission. (Locked missions are not cleared when users attempt to clear all missions in **Recents**.)
25
26- Clear all missions in **Recents**.
27
28- Switch a mission to the foreground.
29
30
31A UIAbility instance corresponds to an independent mission. Therefore, when an application calls [startAbility()](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability) to start a UIAbility, a mission is created.
32
331. To call [missionManager](../reference/apis/js-apis-application-missionManager.md) to manage missions, the home screen application must request the **ohos.permission.MANAGE_MISSIONS** permission. For details about the configuration, see [Declaring Permissions in the Configuration File](../security/accesstoken-guidelines.md#declaring-permissions-in-the-configuration-file).
34
352. You can use **missionManager** to manage missions, for example, listening for mission changes, obtaining mission information or snapshots, and clearing, locking, or unlocking missions.
36
37   ```ts
38   import missionManager from '@ohos.app.ability.missionManager'
39   import { BusinessError } from '@ohos.base';
40
41   let listener: missionManager.MissionListener = {
42     // Listen for mission creation.
43     onMissionCreated: (mission) => {
44       console.info("--------onMissionCreated-------")
45     },
46     // Listen for mission destruction.
47     onMissionDestroyed: (mission) => {
48       console.info("--------onMissionDestroyed-------")
49     },
50     // Listen for mission snapshot changes.
51     onMissionSnapshotChanged: (mission) => {
52       console.info("--------onMissionSnapshotChanged-------")
53     },
54     // Listen for switching the mission to the foreground.
55     onMissionMovedToFront: (mission) => {
56       console.info("--------onMissionMovedToFront-------")
57     },
58     // Listen for mission icon changes.
59     onMissionIconUpdated: (mission, icon) => {
60       console.info("--------onMissionIconUpdated-------")
61     },
62     // Listen for mission name changes.
63     onMissionLabelUpdated: (mission) => {
64       console.info("--------onMissionLabelUpdated-------")
65     },
66     // Listen for mission closure events.
67     onMissionClosed: (mission) => {
68       console.info("--------onMissionClosed-------")
69     }
70   };
71
72   // 1. Register a mission change listener.
73   let listenerId = missionManager.on('mission', listener);
74
75   // 2. Obtain the latest 20 missions in the system.
76   missionManager.getMissionInfos("", 20, (error, missions) => {
77     console.info("getMissionInfos is called, error.code = " + error.code);
78     console.info("size = " + missions.length);
79     console.info("missions = " + JSON.stringify(missions));
80   });
81
82   // 3. Obtain the detailed information about a mission.
83   let missionId = 11; // The mission ID 11 is only an example.
84   let mission = missionManager.getMissionInfo("", missionId).catch((err: BusinessError) => {
85     console.info('${err.code}');
86   });
87
88   // 4. Obtain the mission snapshot.
89   missionManager.getMissionSnapShot("", missionId, (error, snapshot) => {
90     console.info("getMissionSnapShot is called, error.code = " + error.code);
91     console.info("bundleName = " + snapshot.ability.bundleName);
92   })
93
94   // 5. Obtain the low-resolution mission snapshot.
95   missionManager.getLowResolutionMissionSnapShot("", missionId, (error, snapshot) => {
96     console.info("getLowResolutionMissionSnapShot is called, error.code = " + error.code);
97     console.info("bundleName = " + snapshot.ability.bundleName);
98   })
99
100   // 6. Lock or unlock the mission.
101   missionManager.lockMission(missionId).then(() => {
102     console.info("lockMission is called ");
103   });
104
105   missionManager.unlockMission(missionId).then(() => {
106     console.info("unlockMission is called ");
107   });
108
109   // 7. Switch the mission to the foreground.
110   missionManager.moveMissionToFront(missionId).then(() => {
111     console.info("moveMissionToFront is called ");
112   });
113
114   // 8. Clear a single mission.
115   missionManager.clearMission(missionId).then(() => {
116     console.info("clearMission is called ");
117   });
118
119   // 9. Clear all missions.
120   missionManager.clearAllMissions().catch((err: BusinessError) => {
121     console.info('${err.code}');
122   });
123
124   // 10. Deregister the mission change listener.
125   missionManager.off('mission', listenerId, (error) => {
126     console.info("unregisterMissionListener");
127   })
128   ```
129
130
131