• 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
40   let listener = {
41     // Listen for mission creation.
42     onMissionCreated: function (mission) {
43       console.info("--------onMissionCreated-------")
44     },
45     // Listen for mission destruction.
46     onMissionDestroyed: function (mission) {
47       console.info("--------onMissionDestroyed-------")
48     },
49     // Listen for mission snapshot changes.
50     onMissionSnapshotChanged: function (mission) {
51       console.info("--------onMissionSnapshotChanged-------")
52     },
53     // Listen for switching the mission to the foreground.
54     onMissionMovedToFront: function (mission) {
55       console.info("--------onMissionMovedToFront-------")
56     },
57     // Listen for mission icon changes.
58     onMissionIconUpdated: function (mission, icon) {
59       console.info("--------onMissionIconUpdated-------")
60     },
61     // Listen for mission name changes.
62     onMissionLabelUpdated: function (mission) {
63       console.info("--------onMissionLabelUpdated-------")
64     },
65     // Listen for mission closure events.
66     onMissionClosed: function (mission) {
67       console.info("--------onMissionClosed-------")
68     }
69   };
70
71   // 1. Register a mission change listener.
72   let listenerId = missionManager.on('mission', listener);
73
74   // 2. Obtain the latest 20 missions in the system.
75   missionManager.getMissionInfos("", 20, (error, missions) => {
76     console.info("getMissionInfos is called, error.code = " + error.code);
77     console.info("size = " + missions.length);
78     console.info("missions = " + JSON.stringify(missions));
79   });
80
81   // 3. Obtain the detailed information about a mission.
82   let missionId = 11; // The mission ID 11 is only an example.
83   let mission = missionManager.getMissionInfo("", missionId).catch(function (err) {
84     console.info(err);
85   });
86
87   // 4. Obtain the mission snapshot.
88   missionManager.getMissionSnapShot("", missionId, (error, snapshot) => {
89     console.info("getMissionSnapShot is called, error.code = " + error.code);
90     console.info("bundleName = " + snapshot.ability.bundleName);
91   })
92
93   // 5. Obtain the low-resolution mission snapshot.
94   missionManager.getLowResolutionMissionSnapShot("", missionId, (error, snapshot) => {
95     console.info("getLowResolutionMissionSnapShot is called, error.code = " + error.code);
96     console.info("bundleName = " + snapshot.ability.bundleName);
97   })
98
99   // 6. Lock or unlock the mission.
100   missionManager.lockMission(missionId).then(() => {
101     console.info("lockMission is called ");
102   });
103
104   missionManager.unlockMission(missionId).then(() => {
105     console.info("unlockMission is called ");
106   });
107
108   // 7. Switch the mission to the foreground.
109   missionManager.moveMissionToFront(missionId).then(() => {
110     console.info("moveMissionToFront is called ");
111   });
112
113   // 8. Clear a single mission.
114   missionManager.clearMission(missionId).then(() => {
115     console.info("clearMission is called ");
116   });
117
118   // 9. Clear all missions.
119   missionManager.clearAllMissions().catch(function (err) {
120     console.info(err);
121   });
122
123   // 10. Deregister the mission change listener.
124   missionManager.off('mission', listenerId, (error) => {
125     console.info("unregisterMissionListener");
126   })
127   ```
128
129
130