Skip to content

ForegroundTask 创建 FlutterEngine 错误 #353

Open

Description

@saicheng
Image Image

FlutterEngine 的automaticallyRegisterPlugins为true,在FlutterEngine构造方法中会自动调用GeneratedPluginRegistrant.registerWith, 从而将所有plugin都注册到这个FlutterEngine下,FlutterEngine.destroy时会将调用plugin的onDetachedFromEngine方法,这样会影响到一些单例plugin出现异常;例如jpush_flutter

Activity

  1. qxb568 commented on Jul 28, 2025

    @qxb568

    Image Image
    FlutterEngine 的automaticallyRegisterPlugins为true,在FlutterEngine构造方法中会自动调用GeneratedPluginRegistrant.registerWith, 从而将所有plugin都注册到这个FlutterEngine下,FlutterEngine.destroy时会将调用plugin的onDetachedFromEngine方法,这样会影响到一些单例plugin出现异常;例如jpush_flutter

    我也碰到了这个问题,有没有什么好的解决办法啊

  2. saicheng commented on Jul 28, 2025

    @saicheng
    Author

    Image Image
    FlutterEngine 的automaticallyRegisterPlugins为true,在FlutterEngine构造方法中会自动调用GeneratedPluginRegistrant.registerWith, 从而将所有plugin都注册到这个FlutterEngine下,FlutterEngine.destroy时会将调用plugin的onDetachedFromEngine方法,这样会影响到一些单例plugin出现异常;例如jpush_flutter

    我也碰到了这个问题,有没有什么好的解决办法啊

    将ForegroundTask的init中创建FlutterEngine(context), 改为FlutterEngine(context, null, false)

  3. lwy121810 commented on Oct 13, 2025

    @lwy121810

    Image Image
    FlutterEngine 的automaticallyRegisterPlugins为true,在FlutterEngine构造方法中会自动调用GeneratedPluginRegistrant.registerWith, 从而将所有plugin都注册到这个FlutterEngine下,FlutterEngine.destroy时会将调用plugin的onDetachedFromEngine方法,这样会影响到一些单例plugin出现异常;例如jpush_flutter

    我也碰到了这个问题,有没有什么好的解决办法啊

    将ForegroundTask的init中创建FlutterEngine(context), 改为FlutterEngine(context, null, false)

    怎么修复啊?FlutterForegroundTask.init方法里没有FlutterEngine(context)参数啊? flutter_foreground_task: ^9.1.0,

      /// Initialize the [FlutterForegroundTask].
      static void init({
        required AndroidNotificationOptions androidNotificationOptions,
        required IOSNotificationOptions iosNotificationOptions,
        required ForegroundTaskOptions foregroundTaskOptions,
      }) {
        FlutterForegroundTask.androidNotificationOptions =
            androidNotificationOptions;
        FlutterForegroundTask.iosNotificationOptions = iosNotificationOptions;
        FlutterForegroundTask.foregroundTaskOptions = foregroundTaskOptions;
        FlutterForegroundTask.isInitialized = true;
      }
    
  4. saicheng commented on Mar 31, 2026

    @saicheng
    Author

    Image Image
    FlutterEngine 的automaticallyRegisterPlugins为true,在FlutterEngine构造方法中会自动调用GeneratedPluginRegistrant.registerWith, 从而将所有plugin都注册到这个FlutterEngine下,FlutterEngine.destroy时会将调用plugin的onDetachedFromEngine方法,这样会影响到一些单例plugin出现异常;例如jpush_flutter

    我也碰到了这个问题,有没有什么好的解决办法啊

    将ForegroundTask的init中创建FlutterEngine(context), 改为FlutterEngine(context, null, false)

    怎么修复啊?FlutterForegroundTask.init方法里没有FlutterEngine(context)参数啊? flutter_foreground_task: ^9.1.0,

      /// Initialize the [FlutterForegroundTask].
      static void init({
        required AndroidNotificationOptions androidNotificationOptions,
        required IOSNotificationOptions iosNotificationOptions,
        required ForegroundTaskOptions foregroundTaskOptions,
      }) {
        FlutterForegroundTask.androidNotificationOptions =
            androidNotificationOptions;
        FlutterForegroundTask.iosNotificationOptions = iosNotificationOptions;
        FlutterForegroundTask.foregroundTaskOptions = foregroundTaskOptions;
        FlutterForegroundTask.isInitialized = true;
      }
    

    你都搜错文件了,ForegroundTask.kt这个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions