From aaa758d6192d1c56a2b23cd5c6de7cd502197eff Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 11 Dec 2017 17:15:21 -0800 Subject: [PATCH] Check for a detached FlutterNativeView before sending messages (#4445) Fixes https://github.com/flutter/flutter/issues/13481 --- .../platform/android/io/flutter/view/FlutterView.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index bd601cfbf..3c287ce84 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -588,11 +588,12 @@ public class FlutterView extends SurfaceView } private boolean isAttached() { - return mNativeView.isAttached(); + return mNativeView != null && mNativeView.isAttached(); } void assertAttached() { - mNativeView.assertAttached(); + if (!isAttached()) + throw new AssertionError("Platform view is not attached"); } private void preRun() { @@ -857,11 +858,15 @@ public class FlutterView extends SurfaceView @Override public void send(String channel, ByteBuffer message) { - mNativeView.send(channel, message); + send(channel, message, null); } @Override public void send(String channel, ByteBuffer message, BinaryReply callback) { + if (!isAttached()) { + Log.d(TAG, "FlutterView.send called on a detached view, channel=" + channel); + return; + } mNativeView.send(channel, message, callback); }