'How to call a Flutter function from native implementation of Work manager in android?
Have a look at the images. I'm trying to implement the android work manager natively via the method channel. Now, if we start the work manager, I need to call a method on the Flutter side.
I can't find a way to do that. I need flutterEngine for that, and that object should come from FlutterActivity. But there is no way to pass that to the work manager. It lets you pass only data types like int, bool, double, and string.
Solution 1:[1]
You can use the package or implement it similarly with the package https://pub.dev/packages/workmanager
On flutter
- write the top level function
- when initialing app, get callback handle key with
PluginUtilities.getCallbackFromHandle(Function callback) - send the callback handle key to Android
On Android
- save the callback handle key with SharedPreferences
- when you need, create FlutterEngine and run dart code(
engine.dartExecutor.executeDartCallback) using the saved callback handle key
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | wonpyohong |


