diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java index 0068333f8f..80eb7b9cb4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java @@ -607,6 +607,7 @@ public class FlutterFragment extends Fragment { // Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment, // and this Fragment's Activity. + platformPlugin.destroy(); platformPlugin = null; // Destroy our FlutterEngine if we're not set to retain it. diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 46eb7182bc..2b1f48565f 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -561,11 +561,16 @@ public class FlutterView extends FrameLayout { } Log.d(TAG, "Detaching from Flutter Engine"); + // Disconnect and clean up the AccessibilityBridge. + accessibilityBridge.release(); + accessibilityBridge = null; + // Inform the Android framework that it should retrieve a new InputConnection // now that the engine is detached. The new InputConnection will be null, which // signifies that this View does not process input (until a new engine is attached). // TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin textInputPlugin.getInputMethodManager().restartInput(this); + textInputPlugin.destroy(); // Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface. didRenderFirstFrame = false; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java index 42fdd581ab..17e27f69ba 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java @@ -46,7 +46,7 @@ public class TextInputPlugin { // target is a platform view. See the comments on lockPlatformViewInputConnection for more details. private boolean isInputConnectionLocked; - // TODO(mattcarroll): change @Nullable to @NonNull once new embedding integrates PlatformViewsController. + // TODO(mattcarroll): change @Nullable to @NonNull once new embedding integrates PlatformViewsController (#34286). public TextInputPlugin(View view, @NonNull DartExecutor dartExecutor, @Nullable PlatformViewsController platformViewsController) { mView = view; mImm = (InputMethodManager) view.getContext().getSystemService( @@ -85,7 +85,7 @@ public class TextInputPlugin { } }); this.platformViewsController = platformViewsController; - // TODO(mattcarroll): remove if-statement once new embedding integrates PlatformViewsController. + // TODO(mattcarroll): remove if-statement once new embedding integrates PlatformViewsController (#34286). if (platformViewsController != null) { platformViewsController.attachTextInputPlugin(this); } @@ -127,7 +127,7 @@ public class TextInputPlugin { * The TextInputPlugin instance should not be used after calling this. */ public void destroy() { - // TODO(mattcarroll): Remove if-statement once new embedding integrates PlatformViewsController. + // TODO(mattcarroll): Remove if-statement once new embedding integrates PlatformViewsController (#34286). if (platformViewsController != null) { platformViewsController.detachTextInputPlugin(); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 4f2672a82c..3ca13ec44a 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -94,6 +94,15 @@ public class PlatformPlugin implements ActivityLifecycleListener { mEnabledOverlays = DEFAULT_SYSTEM_UI; } + /** + * Releases all resources held by this {@code PlatformPlugin}. + *
+ * Do not invoke any methods on a {@code PlatformPlugin} after invoking this method. + */ + public void destroy() { + this.platformChannel.setPlatformMessageHandler(null); + } + private void playSystemSound(PlatformChannel.SoundType soundType) { if (soundType == PlatformChannel.SoundType.CLICK) { View view = activity.getWindow().getDecorView();