window.getLastWindow(getContext(this), (err: BusinessError, currentWindow) => { const errCode: number = err.code; if (errCode) { Logger.error(TAG, `Failed to obtain the top window. Cause code: ${err.code}, message: ${err.message}`); return; } Logger.debug(TAG, 'Succeeded in obtaining the top window. Data: ' + JSON.stringify(currentWindow)); currentWindow.on('windowEvent', (data) => { if(data == window.WindowEventType.WINDOW_DESTROYED){ // TODO 窗口销毁在此做操作 } }); });
UIAbility的生命周期:UIAbility.onPrepareToTerminate