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 9ccbd2c3f5c9e40aaa97342a02b171ee54a6d4af..39925215232b2fe0d9cb74f1ab339ae014db7f56 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 af0946ca03adcd28b6735e09ffcd05345c77c9eb..7be1d1994bee56c5137df8c1347f0d31ac8bacf7 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); }