import AbilityLifecycleCallback from "@ohos:app.ability.AbilityLifecycleCallback"; import HashSet from "@ohos:util.HashSet"; import hilog from '@ohos:hilog'; export class AppLifecycleManager extends AbilityLifecycleCallback { constructor() { super(...arguments); this.lifecycleObservers = new HashSet(); this.active = false; } addObserver(a1) { this.lifecycleObservers.add(a1); } removeObserver(z) { this.lifecycleObservers.remove(z); } isAppActive() { return this.active; } onWindowStageActive(v, w) { hilog.debug(0x0000, "CameraX", "MyAbilityLifecycleCallback onWindowStageActive"); this.lifecycleObservers.forEach((y) => { y?.onWindowStageActive(); }); this.active = true; } onWindowStageInactive(r, s) { hilog.debug(0x0000, "CameraX", "MyAbilityLifecycleCallback onWindowStageInactive"); this.lifecycleObservers.forEach(async (u) => { u?.onWindowStageInactive(); }); this.active = false; } onAbilityBackground(q) { hilog.debug(0x0000, "CameraX", "MyAbilityLifecycleCallback onAbilityBackground"); } onAbilityForeground(n) { hilog.debug(0x0000, "CameraX", "MyAbilityLifecycleCallback onAbilityForeground"); this.lifecycleObservers.forEach((p) => { p?.onAbilityForeground(); }); } } 