diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 925e2a8d72..66e98087c4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -461,8 +461,11 @@ public class FlutterJNI { @UiThread public void dispatchEmptyPlatformMessage(String channel, int responseId) { - ensureAttachedToNative(); - nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId); + if (isAttached()) { + nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId); + } else { + Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId); + } } // Send an empty platform message to Dart. @@ -474,14 +477,17 @@ public class FlutterJNI { @UiThread public void dispatchPlatformMessage(String channel, ByteBuffer message, int position, int responseId) { - ensureAttachedToNative(); - nativeDispatchPlatformMessage( - nativePlatformViewId, - channel, - message, - position, - responseId - ); + if (isAttached()) { + nativeDispatchPlatformMessage( + nativePlatformViewId, + channel, + message, + position, + responseId + ); + } else { + Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId); + } } // Send a data-carrying platform message to Dart.