Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
140 stars 105 forks source link

Error when openning the app in background: FlutterJNI was detached from native C++ #203

Closed sajjadintel closed 1 month ago

sajjadintel commented 6 months ago

Hi, I'm using https://github.com/hezbr/easy_sms_receiver for listen for receiving SMS, so when a new SMS is received I can open a new page of the app using launchApp.

  @override
  void onStart(DateTime timestamp, SendPort? sendPort) async {
    DartPluginRegistrant.ensureInitialized();
    final plugin = EasySmsReceiver.instance;
    plugin.listenIncomingSms(
      onNewMessage: (message) async {
        final SharedPreferences preferences  = await SharedPreferences.getInstance();
        await preferences.remove('deviceAlert');
        await preferences.setString("deviceAlert", "rec");
        print("You have new message");
        FlutterForegroundTask.launchApp("/alert");
      },
    );
  }

everything is working fine and I get first SMS, then app is opened and shows alert page. but when I close it and I get the second SMS it will show this error:

Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: easy_sms_receiver. Response ID: 9