diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 00e9bcc2666e5801ec1fda6dc4397671a615307d..5e152a6671f47509ac885eadf40cf8e806a3f3c4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -34,6 +34,7 @@ import { RootDvModeManager } from '../../plugin/platform/RootDvModelManager'; import { Configuration } from '@ohos.app.ability.Configuration'; const TAG = "FlutterAbility"; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * flutter ohos基础ability,请在让主ability继承自该类。 * 该类主要职责: @@ -68,14 +69,18 @@ export class FlutterAbility extends UIAbility implements Host { this?.delegate?.sendSettings(); if (this.stillAttachedForEvent("onCreate")) { - this?.delegate?.onCreate(); + this.delegate?.onCreate(); } console.log('MyAbility onCreate'); // globalThis.applicationContext = this.context.getApplicationContext(); + this.context.eventHub.on(EVENT_BACK_PRESS, () => { + this.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + }); } onDestroy() { + this.context.eventHub.off(EVENT_BACK_PRESS); if (this.stillAttachedForEvent("onDestroy")) { this?.delegate?.onDestroy(); }