Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Messaging
Which platforms are affected?
Android
Description
_firebaseMessagingForegroundHandler and _firebaseMessagingBackgroundHandler are fired multiple times for the same silent (data-only) notification - with firebase messaging 15.2.1
I'm reproducing the issue on android sdk34 Xiaomim Mi Lite 5g, though I saw past similar issues on IOS and this may still affect IOS as well.
Honestly, I’d rather deal with duplicate notifications than miss them entirely.
As a workaround, I’ve implemented a simple cache of notification IDs and filter out duplicates before displaying any alerts. Example code below:
const String kFirebaseNotificationIds = 'firebase_notification_ids';
...
final content = notification.content as ChatNotificationContent;
debugPrint(“DEBUG notification content ${content.id}");
final notificationIds = SharedPrefs.instance.getStringList(kFirebaseNotificationIds) ?? [];
if (notificationIds.contains(content.id)) {
debugPrint("DEBUG skip duplicate notification");
return;
} else {
notificationIds.add(content.id);
SharedPrefs.instance.setStringList(kFirebaseNotificationIds, notificationIds);
...
// ShowNotification with flutter local notification
}
...
// Clear kFirebaseNotificationIds when app is paused
I'm still experiencing issues with Android intermittently throttling or blocking push notifications, only to deliver them all at once later. Disabling battery optimizations and enabling autostart improves reliability somewhat, but overall, notification delivery on Android remains inconsistent.
It would be great if the Firebase team could collaborate with the Android team to address this — ideally establishing a more consistent behavior across devices and limiting the ability of manufacturers to interfere with notification delivery mechanisms.
Reproducing the issue
Send a notification to your device.
Firebase Core version
^3.1.1
Flutter Version
3.24.5
Relevant Log Output
Flutter dependencies
Expand Flutter dependencies
snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
No response