Hi,
I use Workmanager to run a background independent isolate. The setup is like this:
/// Entry point to background isolate
@pragma('vm:entry-point')
void callbackDispatcher() {
Workmanager().executeTask(backgroundMain);
}
/// Starts background isolate to host background parts of components
/// This function is executed in foreground and ensures proper start of background
/// isolate
Future<DuplexPort> initAppBackground(String logFile) async {
Logger.root.info("Starting background isolate");
Workmanager().initialize(callbackDispatcher, isInDebugMode: false);
await Workmanager().registerOneOffTask("task-identifier", "app",
inputData: {'logFile': logFile});
final port = await _initPort('app-to-background', 'app-from-background');
return port;
}
/// Main function executed in the background
Future<bool> backgroundMain(String task, JSON? inputData) async {
...
}
I've noticed the callbackDispatcher runs even before Workmanager().initialize() is called and as a consequence inputData in backgroundMain is just null. Is it normal behavior?
Hi, I use
Workmanager
to run a background independent isolate. The setup is like this:I've noticed the
callbackDispatcher
runs even beforeWorkmanager().initialize()
is called and as a consequenceinputData
inbackgroundMain
is justnull
. Is it normal behavior?