Skip to content

FlutterNativeView "send" method should not suppress detached view exception #35628

@diesersamat

Description

@diesersamat

This issue is about an issue with Flutter API in native Android code.

In FlutterNativeView.java there is a function called send(String channel, ByteBuffer message, BinaryReply callback):

public void send(String channel, ByteBuffer message, BinaryReply callback) {
        if (!this.isAttached()) {
            Log.d("FlutterNativeView", "FlutterView.send called on a detached view, channel=" + channel);
        } else {
            this.dartExecutor.send(channel, message, callback);
        }
    }

As you can see, if the view is not attached, nothing happens. I think we should call callback with an error message or maybe return something from the function.

I faced this issue trying to call channel.invokeMethod("launch", type); — if the view is not attached, there is no way to react to that case. Even if you call channel.invokeMethod("launch", type, callback);, the callback will not return onError, because, as you saw, in the case when the view is not attached, nothing will happen.

Steps to Reproduce

You can face the issue, for example, in quick_actions plugin.

  1. Install the example app and run it on Android
  2. If you try to use the Shortcut item, it should work fine
  3. Now, open the app again, and click Back button
  4. Click the Shortcut icon again
    As you can see, the quick action will not be called and the app will not be opened this time. The main issue here is that the quick_actions plugin tries to call channel.invokeMethod("launch", type);, but the view has been already detached and the only thing that happens is "FlutterView.send called on a detached view, channel= message in Logcat. And there is no way to fix this behavior because there is no way to react to such a case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineflutter/engine related. See also e: labels.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallywaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions