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 07a374a7109e9a1ffcd5680220534c9796681e64..7bf5f292406e34e9f1b1e64b068102f112510afd 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继承自该类。 * 该类主要职责: @@ -73,9 +74,13 @@ export class FlutterAbility extends UIAbility implements Host { 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(); }