I want to call a native method which I have made in the MainActivity. While the app is in the foreground, everything works fine, but when the app is in the background it doesn't even go into the MainActivity. So it doesn't log there either. I call the method like this: MethodChannel('de.my').invokeMethod("getCurrentNotificationGroups"); ..and this is also where the error message appears I get the following error message: FlutterFire notification: An error has occurred in your background messaging handler: **MissingPluginException(No implementation found for method **getCurrentNotificationGroups on channel de.my) Do any of you have experience with calling native methods(MainActivity) in the background?

I red online: The problem is that if your app starts executing code while it is stopped, as happens with Firebase's onBackgroundMessageHandler, then MainActivity is not called and so your MethodChannel does not exist.

I think this is the problem, however I don't know how to solve this, do any of you have any ideas?

This is my Background handler which is trigged at

FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  WidgetsFlutterBinding.ensureInitialized();
  await AppNotification.convertFirebaseToLocalNotification(message);
}

This is in my MainActivity.java

@Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);

        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "de.my")
                .setMethodCallHandler((methodCall, result) -> {
                    Log.d("MethodChannel", "Received method call: " + methodCall.method);

                    switch (methodCall.method) {
                        case "clearNotifications": {
                            clearNotifications();
                            result.success(true);
                            break;
                        }
                        case "getCurrentNotificationGroups": {
                            List<String> notificationGroups = getCurrentNotificationGroups();
                            result.success(notificationGroups);
                            break;
                        }
                        default: {
                            result.notImplemented();
                            break;
                        }
                    }
                });
    }

I did uninstall and re-install, flutter clean, but nothing worked My goal is simply that the method is also called in the background on android, because everything works fine in the foreground. I have scoured the internet and tried everything possible, but nothing works.

0

There are 0 answers