harmony 鸿蒙Window Subsystem ChangeLog

  • 2023-02-03
  • 浏览 (435)

Window Subsystem ChangeLog

cl.window.1 Change of Window Stage Lifecycle Listener Types

Changed the enumerated listener types of the window stage lifecycle in version 4.0.1.1 and later.

Change Impacts

Application lifecycle listeners developed using FOREGROUND and BACKGROUND in versions earlier than 4.0.1.1 will be invalidated in version 4.0.1.1 and later.

Key API/Component Changes

WindowStageEventType9+

Before change:

Name Value Description
FOREGROUND 1 The window stage is running in the foreground.
BACKGROUND 4 The window stage is running in the background.

After change: |Name|Value|Description | |——|—-|———-| |SHOWN|1 |The window stage is running in the foreground.| |HIDDEN|4 |The window stage is running in the background.|

Adaptation Guide

When registering lifecycle listeners, change the foreground and background event types to SHOWN and HIDDEN, respectively.

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

class myAbility extends Ability {
    onWindowStageCreate(windowStage) {
        console.log('onWindowStageCreate');
        try {
            windowStage.on('windowStageEvent', (stageEventType) => {
                switch (stageEventType) {
                    case window.WindowStageEventType.SHOWN:
                        console.log("windowStage shown");
                        break;
                    case window.WindowStageEventType.ACTIVE:
                        console.log("windowStage active");
                        break;
                    case window.WindowStageEventType.INACTIVE:
                        console.log("windowStage inActive");
                        break;
                    case window.WindowStageEventType.HIDDEN:
                        console.log("windowStage hidden");
                        break;
                    default:
                        break;
                }
        	} )
        } catch (exception) {
            console.error('Failed to enable the listener for window stage event changes. Cause:' +
                JSON.stringify(exception));
        };
    }
};

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Account Subsystem ChangeLog

0  赞