flutter_isolate
flutter_isolate copied to clipboard
Restore multiple instances of flutter_isolate plugin
Our project already runs multiple isolates in the background (driven by native components, like BT connection or Android lifecycle). These components are long-lived and need to co-exist with the UI as well.
We found that on iOS, only one of the sides (BG or FG) will be able to control isolates using flutter_isolate
.
This is most likely happening due to the plugin having a static instance and not initializing the control channel anymore when the instance already exists.
This MR improves the behavior and should unblock us from using it.
@ened can you provide a bit more detail about your use case? The current assumption is that registerWithRegistrar is called once (and only once) in the app lifecycle, but it sounds like this assumption isn't appropriate for your design. It would be helpful for me to understand how you're working with isolates in both the foreground/background.
Also, have you checked whether registering a subsequent method channel with the same name doesn't interfere the first?
@nmfisher whenever a Flutter Isolate is started, it could belong to a full Flutter Engine including plugins. This is the case for example in the workmanager
plugin. Over there, the Android system allocates resources for an App to run in the background, which ends up being managed by workmanager
, and in order to run Dart code, it starts a full Flutter Engine, including plugins. This can even happen when the App is already in foreground.
Similarly, for push notifications using firebase_messaging (when receiving a notification while App is dead).
In our use case, we had a long-running BT connection (and associated FG service with a Flutter Engine) which provides context to run Dart code long term and both the FG and BG sides wanted to execute additional isolates using this flutter_isolate
plugin. It was prevented by the assumption that registerWithRegistrar
is only called once, as it's actually being called "only once per Flutter Engine".
Thanks @ened - I think I understand your issue now:
- you're working with isolate(s) spawned by flutter_isolate, and isolate(s) spawned by separate Flutter Engine(s)/plugin(s),
- plugins created in the former won't be able to communicate with control channels created in the latter (and vice versa).
Is everything working correctly on Android?
Thanks @ened - I think I understand your issue now:
you're working with isolate(s) spawned by flutter_isolate, and isolate(s) spawned by separate Flutter Engine(s)/plugin(s),
plugins created in the former won't be able to communicate with control channels created in the latter (and vice versa).
Is everything working correctly on Android?
Yes we shipped production apps with the fork without issues.
This PR and https://github.com/rmawatson/flutter_isolate/pull/118 should be merged to master ASAP, they unbreak this plugin for a lot of functionality.
Thanks @ened