diff --git a/zh-cn/application-dev/reference/apis/js-apis-appmanager.md b/zh-cn/application-dev/reference/apis/js-apis-appmanager.md index 7688a46b0bec337a7cecc801e2855afd576328c6..8f5fdf724cfe904c23285efcfce9e9cc68996192 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-appmanager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-appmanager.md @@ -210,7 +210,7 @@ getProcessRunningInfos(callback: AsyncCallback\>): vo registerApplicationStateObserver(observer: ApplicationStateObserver): number; -注册应用程序状态观测器。 +注册全部应用程序状态观测器。 **需要权限**:ohos.permission.RUNNING_STATE_OBSERVER @@ -244,6 +244,48 @@ registerApplicationStateObserver(observer: ApplicationStateObserver): number; const observerCode = app.registerApplicationStateObserver(applicationStateObserver); console.log('-------- observerCode: ---------', observerCode); + ``` + +## appManager.registerApplicationStateObserver9+ + +registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameList: Array): number; + +注册指定应用程序状态观测器。 + +**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**系统API**:该接口为系统接口,三方应用不支持调用。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| observer | ApplicationStateObserver | 否 | 返回观察者的数字代码。 | +| bundleNameList | Array | 否 | 表示需要注册监听的bundleName数组。最大值128。 | + +**示例:** + + ```js + var applicationStateObserver = { + onForegroundApplicationChanged(appStateData) { + console.log('------------ onForegroundApplicationChanged -----------', appStateData); + }, + onAbilityStateChanged(abilityStateData) { + console.log('------------ onAbilityStateChanged -----------', abilityStateData); + }, + onProcessCreated(processData) { + console.log('------------ onProcessCreated -----------', processData); + }, + onProcessDied(processData) { + console.log('------------ onProcessDied -----------', processData); + } + } + var bundleNameList = ['bundleName1', 'bundleName2']; + const observerCode = app.registerApplicationStateObserver(applicationStateObserver, bundleNameList); + console.log('-------- observerCode: ---------', observerCode); + ``` ## appManager.unregisterApplicationStateObserver8+