harmony 鸿蒙MissionListener (System API)

  • 2025-06-12
  • 浏览 (2)

MissionListener (System API)

The MissionListener module defines the listeners used to observe the mission status. The listeners can be registered by using on.

NOTE

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. The APIs provided by this module are system APIs.

Modules to Import

import { missionManager } from '@kit.AbilityKit';

Attributes

System API: This is a system API.

System capability: SystemCapability.Ability.AbilityRuntime.Mission

Name Type Mandatory Description
onMissionCreated function No Called when the system creates a mission.
onMissionDestroyed function No Called when the system destroys the mission.
onMissionSnapshotChanged function No Called when the system updates the mission snapshot.
onMissionMovedToFront function No Called when the system moves the mission to the foreground.
onMissionLabelUpdated9+ function No Called when the system updates the mission label.
onMissionIconUpdated9+ function No Called when the system updates the mission icon.
onMissionClosed9+ function No Called when the system closes the mission.

Example

import { missionManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let listener: missionManager.MissionListener = {
  onMissionCreated: (mission) => {
    console.log(`onMissionCreated mission: ${JSON.stringify(mission)}`);
  },
  onMissionDestroyed: (mission) => {
    console.log(`onMissionDestroyed mission: ${JSON.stringify(mission)}`);
  },
  onMissionSnapshotChanged: (mission) => {
    console.log(`onMissionSnapshotChanged mission: ${JSON.stringify(mission)}`);
  },
  onMissionMovedToFront: (mission) => {
    console.log(`onMissionMovedToFront mission: ${JSON.stringify(mission)}`);
  },
  onMissionLabelUpdated: (mission) => {
    console.log(`onMissionLabelUpdated mission: ${JSON.stringify(mission)}`);
  },
  onMissionIconUpdated: (mission, icon) => {
    console.log(`onMissionIconUpdated mission: ${JSON.stringify(mission)}`);
    console.log(`onMissionIconUpdated icon: ${JSON.stringify(icon)}`);
  },
  onMissionClosed: (mission) => {
    console.log(`onMissionClosed mission: ${JSON.stringify(mission)}`);
  }
};

try {
  let listenerId = missionManager.on('mission', listener);
} catch (paramError) {
  console.error(`error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

0  赞