From bee45b962b4087836bf41daa0071648dc861c78a Mon Sep 17 00:00:00 2001 From: zhoujiaying Date: Wed, 29 Nov 2023 11:32:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8Restoration?= =?UTF-8?q?ScopeId=E5=90=8E=E9=BB=91=E5=B1=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoujiaying --- .../engine/systemchannels/RestorationChannel.ets | 8 +++++--- .../main/ets/embedding/ohos/FlutterAbilityDelegate.ets | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets index 9ccbd2c3f5..3992521523 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets @@ -58,12 +58,12 @@ export default class RestorationChannel { // Holds the most current restoration data which may have been provided by the engine // via "setRestorationData" or by the framework via the method channel. This is the data the // framework should be restored to in case the app is terminated. - private restorationData: Uint8Array = new Uint8Array(); + private restorationData: Uint8Array; private channel: MethodChannel | null = null; private pendingFrameworkRestorationChannelRequest: MethodResult | null = null; private engineHasProvidedData: boolean = false; private frameworkHasRequestedData: boolean = false; - private handler: MethodCallHandler = new RestorationChannelMethodCallHandler(this.restorationData); + private handler: MethodCallHandler; constructor(channelOrExecutor: MethodChannel | DartExecutor, waitForRestorationData: boolean) { if (channelOrExecutor instanceof MethodChannel) { @@ -72,6 +72,8 @@ export default class RestorationChannel { this.channel = new MethodChannel(channelOrExecutor, RestorationChannel.CHANNEL_NAME, StandardMethodCodec.INSTANCE); } this.waitForRestorationData = waitForRestorationData; + this.restorationData = new Uint8Array(1).fill(0); + this.handler = new RestorationChannelMethodCallHandler(this.restorationData); this.channel.setMethodCallHandler(this.handler); } @@ -121,7 +123,7 @@ export default class RestorationChannel { * state prior to the hot restart will get restored. */ clearData() { - this.restorationData = new Uint8Array(); + this.restorationData = new Uint8Array(1).fill(0); } } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets index af0946ca03..7be1d1994b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets @@ -135,7 +135,7 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { onRestoreInstanceState(want: Want) { let frameworkState = want.parameters != null ? want.parameters[FRAMEWORK_RESTORATION_BUNDLE_KEY] as Uint8Array - : new Uint8Array(); + : new Uint8Array(1).fill(0); if (this.host?.shouldRestoreAndSaveState()) { this.flutterEngine?.getRestorationChannel()?.setRestorationData(frameworkState); } -- Gitee