Invoke Native Android when App in background or closed

I’m using Firebase and flutter local notifications to display notifications I get from my server. I wanted to display certain notifications inside the conversation part of the android notifications, so I made a native kotlin call using the method channel to create a shortcut for this:


  static Future<String?> _createConversationShortcut(
      String personName, String personIconPath) async {
    const platform = MethodChannel('...');
    String result;
    try {
      result = await platform.invokeMethod('createConversationShortcut', {
        'personName': personName,
        'personIcon': personIconPath,
    } on PlatformException catch (e) {
      return null;
    return result;

I call the method _createConversationShortcut to create a shortcut natively and then use the shortcut ID in the AndroidNotificationDetails so that the notification is in the Conversation part
          android: AndroidNotificationDetails(
            icon: '@drawable/is_notification',
            category: 'msg',
            shortcutId: shortcutId,
            styleInformation: MessagingStyleInformation(
              groupConversation: false,
              conversationTitle: 'Neue Privatnachricht',
              messages: messages,
            //setAsGroupSummary: true,
        payload: json.encode(payload),


class MainActivity: FlutterActivity() {

    private val CHANNEL = "..."

    private fun createConversationShortcut(personName: String, personIcon: String): String {
        val person = Person.Builder()
        val shortcut = ShortcutInfoCompat.Builder(context, personName.toLowerCase(Locale.ROOT).replace(" ", "_") + "_shortcut")
        ShortcutManagerCompat.addDynamicShortcuts(context, listOf(shortcut))

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
            if (call.method == "createConversationShortcut") {
                val personName = call.argument<String>("personName")
                val personIcon = call.argument<String>("personIcon")
                if (personName != null && personIcon != null) {
                    val shortcutId = createConversationShortcut(personName, personIcon)
                } else {
                    result.error("argument-error", "Too few arguments", null)
            } else {

This works perfectly when the app is in the foreground but when my app is in the backgroudn or closed I get an ImplementationError because MainActivity doesn’t exist.

My question now is, how can I invoke the method channel, when the app is in the background or closed?
I read that I need to create a service for that but I have no clue how I can set the method call handler from inside the service.
Can anyone please help my with this?