openharmony 鸿蒙 js-apis-inner-application-processData

2025-06-12 浏览 (1)

ProcessData

The ProcessData module defines process data. If a lifecycle change listener is registered by calling on, the onProcessCreated callback in ApplicationStateObserver is invoked when the lifecycle of an application or ability changes.

NOTE

The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

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

Properties

System capability: SystemCapability.Ability.AbilityRuntime.Core

NameTypeMandatoryDescription
pidnumberYesProcess ID.
bundleNamestringYesBundle name of the application.
uidnumberYesUID of the application.
isContinuousTaskbooleanYesWhether the task is a continuous task. The value true means that the task is a continuous task, and false means the opposite.
isKeepAlivebooleanYesWhether the process is a resident task. The value true means that the process is a resident, and false means the opposite.
statenumberYesApplication state. The options are as follows:
0: newly created.
1: ready.
2: running in the foreground.
4: running in the background.
5: terminated.

Example

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

let observerCode = appManager.on('applicationState', {
  onForegroundApplicationChanged(appStateData) {
    console.log(`onForegroundApplicationChanged, appStateData: ${JSON.stringify(appStateData)}.`);
  },
  onAbilityStateChanged(abilityStateData) {
    console.log(`onAbilityStateChanged, abilityStateData: ${JSON.stringify(abilityStateData)}.`);
  },
  onProcessCreated(processData) {
    console.log(`onProcessCreated, processData: ${JSON.stringify(processData)}.`);
  },
  onProcessDied(processData) {
    console.log(`onProcessDied, processData: ${JSON.stringify(processData)}.`);
  },
  onProcessStateChanged(processData) {
    console.log(`onProcessStateChanged, processData.pid : ${JSON.stringify(processData.pid)}.`);
    console.log(`onProcessStateChanged, processData.bundleName : ${JSON.stringify(processData.bundleName)}.`);
    console.log(`onProcessStateChanged, processData.uid : ${JSON.stringify(processData.uid)}.`);
    console.log(`onProcessStateChanged, processData.isContinuousTask : ${JSON.stringify(processData.isContinuousTask)}.`);
    console.log(`onProcessStateChanged, processData.isKeepAlive : ${JSON.stringify(processData.isKeepAlive)}.`);
  },
  onAppStarted(appStateData) {
    console.log(`onAppStarted, appStateData: ${JSON.stringify(appStateData)}.`);
  },
  onAppStopped(appStateData) {
    console.log(`onAppStopped, appStateData: ${JSON.stringify(appStateData)}.`);
  }
});

你可能感兴趣的鸿蒙文章

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

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/9IDh2A