registerBackgroundMessageHandler method
Registers a callback to handle background messages.
For Android this uses isolates and requires a top level function.
Implementation
@override
Future<void> registerBackgroundMessageHandler(
BackgroundMessageHandler handler) async {
_onBackgroundMessage = handler;
if (defaultTargetPlatform != TargetPlatform.android) {
return;
}
if (!_bgHandlerInitialized) {
_bgHandlerInitialized = true;
final CallbackHandle bgHandle =
PluginUtilities.getCallbackHandle(_messagingCallbackDispatcher)!;
final CallbackHandle userHandle =
PluginUtilities.getCallbackHandle(handler)!;
await methodChannel.invokeMethod(
'AzNotificationHub.startBackgroundIsolate',
{
'pluginCallbackHandle': bgHandle.toRawHandle(),
'userCallbackHandle': userHandle.toRawHandle(),
},
);
}
}