Skip to content

Commit 613d864

Browse files
fix(android): register incoming-call handler on every engine messenger
bindChannelIfUnbound early-returned on later engines, so a FlutterFire background isolate's messenger never got setMethodCallHandler, breaking Dart->Native calls (MissingPluginException) from an FCM background handler. Always register the incoming handler per engine while keeping the outgoing channel pinned to the first engine (preserves the #1138 Native->Dart fix). Also fix the .gitignore comment to reference examples/demo_fm. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2133c51 commit 613d864

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dlcov.log
3232
**/workspace-state.json
3333

3434
# Per-developer Firebase config for issue #1138 repro scaffolding
35-
# (only needed because firebase_messaging is wired into examples/demo;
35+
# (only needed because firebase_messaging is wired into examples/demo_fm;
3636
# OneSignal itself does NOT need this file).
3737
**/google-services.json
3838
**/GoogleService-Info.plist

android/src/main/java/com/onesignal/flutter/FlutterMessengerResponder.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@ abstract class FlutterMessengerResponder {
1414
BinaryMessenger messenger;
1515

1616
/**
17-
* #1138: bind the shared channel only on the first engine. These responders are
18-
* process-global singletons but {@code registerWith} runs once per Flutter
19-
* engine; FlutterFire's headless background engine would otherwise rebind the
20-
* channel to an isolate with no listeners and drop native callbacks.
17+
* #1138: bind the outgoing shared channel only on the first engine. These
18+
* responders are process-global singletons but {@code registerWith} runs once
19+
* per Flutter engine; FlutterFire's headless background engine would otherwise
20+
* rebind the channel to an isolate with no listeners and drop native callbacks.
21+
*
22+
* <p>The incoming-call handler is still registered on every engine's messenger
23+
* so Dart->Native calls work from any isolate (e.g. an FCM background handler),
24+
* matching the pre-#1138 behavior; only the outgoing Native->Dart channel stays
25+
* pinned to the first engine.
2126
*
2227
* @return true if this call performed the initial bind.
2328
*/
2429
boolean bindChannelIfUnbound(BinaryMessenger messenger, String channelName, MethodCallHandler handler) {
30+
MethodChannel channel = new MethodChannel(messenger, channelName);
31+
channel.setMethodCallHandler(handler);
2532
if (this.channel != null) {
2633
return false;
2734
}
2835
this.messenger = messenger;
29-
this.channel = new MethodChannel(messenger, channelName);
30-
this.channel.setMethodCallHandler(handler);
36+
this.channel = channel;
3137
return true;
3238
}
3339

0 commit comments

Comments
 (0)