alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
116 stars 142 forks source link

BUG: FlutterJNI was detached from native C++ #80

Open evanblasband opened 3 years ago

evanblasband commented 3 years ago

Everything seems to work on both platforms except for android when app is stopped. I will be monitoring and scanning for iBeacons with the app open and see prints successfully, however once I completely close the app I get the following print error

W/FlutterJNI(30164): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter_beacon_event. Response ID: 0
W/FlutterJNI(13542): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter_beacon_event_monitoring. Response ID: 0

then once I bring the app back it works again. Has anyone else experienced this?

EDIT: my guess is that when the app is closed the activity gets detached and therefore, the channels are being closed (FlutterBeaconPlugin.java)

private void teardownChannels() {
    if (activityPluginBinding != null) {
      activityPluginBinding.removeActivityResultListener(this);
      activityPluginBinding.removeRequestPermissionsResultListener(this);
    }

    platform = null;
    beaconBroadcast = null;

    channel.setMethodCallHandler(null);
    eventChannel.setStreamHandler(null);
    eventChannelMonitoring.setStreamHandler(null);
    eventChannelBluetoothState.setStreamHandler(null);
    eventChannelAuthorizationStatus.setStreamHandler(null);

    channel = null;
    eventChannel = null;
    eventChannelMonitoring = null;
    eventChannelBluetoothState = null;
    eventChannelAuthorizationStatus = null;

    activityPluginBinding = null;
  }

is there a downside to keeping the eventChannel and eventChannelMonitoring open so that iBeacon events can happen even when the app is killed?

alann-maulana commented 3 years ago

Hi @evanblasband

Those message are regarding Flutter engine https://github.com/flutter/flutter/issues/28651. With the latest release of Flutter, I don't seem to see it again. Is this issue persists?

gmstyle commented 2 years ago

Same problem for me when the app is closed by back button on flutter beta if i use a physical device to work. It not happen on android emulator

Flutter 2.10.0-0.1.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 628f0e3f3a (8 days ago) • 2022-01-11 19:50:05 -0600 Engine • revision 63ca99584a Tools • Dart 2.16.0 (build 2.16.0-134.1.beta) • DevTools 2.9.2

W/FlutterJNI(13495): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter_beacon_event. Response ID: ...

natamvo commented 9 months ago

@alann-maulana we are facing the same error, can you help? can I have your contact? you can search my name on Linkedin Natam Oliveira