Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register plugin from isolate #10

Open
2math opened this issue Jun 2, 2021 · 0 comments
Open

Register plugin from isolate #10

2math opened this issue Jun 2, 2021 · 0 comments

Comments

@2math
Copy link

2math commented Jun 2, 2021

If I want to use another plugin that starts in isolate and auto register plugins(like foreground service), there is an issue.
The problem is that flt_worker requires an activity and crashes on registration, which leads to registering only the plugins that was before it in the GeneratedPluginRegistrant
The problem is here :

          final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
          channel.setMethodCallHandler(new FltWorkerPlugin(registrar.activity()));

I have changed it manually on my side to :

    try {
          final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
          channel.setMethodCallHandler(new FltWorkerPlugin(registrar.activity()));
      } catch (Exception e) {
          Log.e("Error","FltWorkerPlugin.registerWith", e );
      }

And now can see the crash in the logs, but is handled and GeneratedPluginRegistrant can continue with the other plugins. Also I don't use flt_worker from other isolates and above approach is saving me

Btw, I haven't checked if your plugin really needs an activity? If not you can pass a context only. Bellow code does not log a crash when is started from another isolate and also works when I tested it in my app

  public static void registerWith(Registrar registrar) {
      try {
          final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
          channel.setMethodCallHandler(new FltWorkerPlugin(registrar.context()));
      } catch (Exception e) {
          Log.e("Error","FltWorkerPlugin.registerWith", e );
      }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant