harmony 鸿蒙ProcessData

2022-12-22 浏览 (701)

ProcessData

The ProcessData module defines process data. If a lifecycle change listener is registered by calling registerApplicationStateObserver, 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 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import appManager from '@ohos.application.appManager';

Attributes

System capability: SystemCapability.Ability.AbilityRuntime.Core

System API: This is a system API and cannot be called by third-party applications.

NameTypeReadableWritableDescription
pidnumberYesNoProcess ID.
bundleNamestringYesNoBundle name of the application.
uidnumberYesNoUID of the application.
isContinuousTask9+booleanYesNoWhether the task is a continuous task. The value true means that the task is a continuous task, and false means the opposite.
isKeepAlive9+booleanYesNoWhether the process is a resident task. The value true means that the process is a resident, and false means the opposite.
state9+numberYesNoApplication 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 '@ohos.application.appManager';

let observerCode = appManager.registerApplicationStateObserver({
    onForegroundApplicationChanged(appStateData) {
        console.log(`onForegroundApplicationChanged appStateData: ${JSON.stringify(appStateData)}`);
    },
    onAbilityStateChanged(abilityStateData) {
        console.log(`onAbilityStateChanged onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`);
    },
    onProcessCreated(processData) {
        console.log(`onProcessCreated onProcessCreated: ${JSON.stringify(processData)}`);
    },
    onProcessDied(processData) {
        console.log(`onProcessDied onProcessDied: ${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)}`);
    }
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

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