ProcessData


ProcessData

定义进程数据,可以通过registerApplicationStateObserver注册生命周期变化监听后,通过ApplicationStateObserver的onProcessCreated生命周期回调获取。

系统能力:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

系统API:该接口为系统接口,三方应用不支持调用。

名称 类型 可读 可写 说明
pid8+ number 进程ID。
bundleName8+ string Bundle名称。
uid8+ number 用户ID。
isContinuousTask9+ boolean 判断过程是否为连续任务。
isKeepAlive9+ boolean 判断该过程是否保持活跃。

示例:

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);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24