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.

System capability: SystemCapability.Ability.AbilityRuntime.Core

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

Name Type Readable Writable Description
pid8+ number Yes No Process ID.
bundleName8+ string Yes No Bundle name of the application.
uid8+ number Yes No UID of the application.
isContinuousTask9+ boolean Yes No Whether the task is a continuous task. The value true means that the task is a continuous task, and false means the opposite.
isKeepAlive9+ boolean Yes No Whether the process is a resident task. The value true means that the process is a resident, and false means the opposite.

Example

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

let applicationStateObserver = {
    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));
    }
};
let observerCode = appManager.registerApplicationStateObserver(applicationStateObserver);