diff --git a/services/dialog/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts b/services/dialog/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts index fdd7c147..eb18f4ea 100644 --- a/services/dialog/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts +++ b/services/dialog/entry/src/main/ets/ServiceExtAbility/ServiceExtAbility.ts @@ -78,19 +78,19 @@ export default class ServiceExtAbility extends ServiceExtensionAbility { } }); }); + + globalThis.releaseContext = ((): void => { + if (globalThis.context !== null) { + globalThis.extensionWin.destroy(); + globalThis.context.terminateSelf(); + globalThis.context = null; + } + }); } onDestroy(): void { console.log(TAG + 'ServiceExtAbility destroyed'); - this.releaseContext(); - } - - private async releaseContext(): Promise { - if (globalThis.context !== null) { - await globalThis.extensionWin.destroy(); - await globalThis.context.terminateSelf(); - globalThis.context = null; - } + globalThis.releaseContext(); } private async createWindow(name: string, windowType: number, rect): Promise { @@ -111,7 +111,7 @@ export default class ServiceExtAbility extends ServiceExtensionAbility { win.on('windowEvent', (data) => { console.log(TAG + 'windowEvent:' + JSON.stringify(data)); if (data === window.WindowEventType.WINDOW_INACTIVE) { - this.releaseContext(); + globalThis.releaseContext(); } }); await win.moveTo(rect.left, rect.top);