fix(android): unsubscribe click listener when Flutter engine detaches#1140
Merged
Conversation
abdulraqeeb33
approved these changes
Apr 30, 2026
fadi-george
approved these changes
Apr 30, 2026
sherwinski
approved these changes
Apr 30, 2026
|
is there any expectations for this to be merged and released? This will solve a huge bug on my flutter project (android side). thank you very much! |
When the engine is destroyed (e.g. back press) the singleton listener remains subscribed to the native SDK and any subsequent click event fires on a detached channel and is dropped. Removing the listener in onDetachedFromEngine lets the native SDK queue the click instead, so it replays correctly when Dart re-registers via addNativeClickListener after the engine reattaches.
d78b12b to
793ced8
Compare
Contributor
Author
|
Re-tested using Android release 5.8.1
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One Line Summary
Closes #1138 — unsubscribe the notification click listener when the Flutter engine detaches so click events that arrive while the engine is dead are queued and replayed on relaunch.
Details
Motivation
Since #1102 made
OneSignalNotificationsa singleton, the click listener stays subscribed to the native Android SDK across engine detach/reattach cycles. When the user backgrounds the app via the back button:onClickon the listener, which tries to send a platform message on the now-detachedBinaryMessenger. The message is dropped (logged asFlutterJNI was detached from native C++. Could not send.).Customers report that prior to 5.3.6 the click listener fired correctly in this scenario.
Scope
OneSignalNotifications.onDetachedFromEngine()which callsOneSignal.getNotifications().removeClickListener(this).OneSignalPlugin.onDetachedFromEngine().unprocessedOpenedNotifsqueues the click event (no subscriber), andaddExternalClickListenerreplays it when Dart callsaddClickListener→addNativeClickListener→registerClickListenerafter the engine reattaches.Dependency
This PR depends on OneSignal/OneSignal-Android-SDK#2632, which clears
unprocessedOpenedNotifsafter replay. Without that Android SDK fix, the queue accumulates across back-press cycles and each newaddClickListenercall refires every previously delivered event. The Android SDK release containing #2632 must land first, and thecom.onesignal:OneSignaldependency inandroid/build.gradlemust be bumped to that version before this fix is shipped.Manual testing
Reproduced and verified on the
examples/demo_podsapp on an Android emulator (API 35):NotificationsManager.removeClickListener).addNativeClickListener, andNotification clicked: ...is logged.Affected code checklist
Checklist
Overview
Testing
Final pass