Skip to content

Firebase Cloud Messaging] getInitialMessage() returns non null notification even after it is consumed.  #10768

Open
@suhail600

Description

@suhail600
Future<void> onSelectBackgroundNotification() async {
    RemoteMessage? message =
        await FirebaseMessaging.instance.getInitialMessage();

    if (message?.notification != null) {
      _handleMessage(message!.data);
      message = null;
      log('background Message has been opened');
    }

    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
      RemoteNotification? notification = message.notification;
      if (notification != null) {
        _handleMessage(message.dat,);
      }
    });
  }
  1. the code runs when app is in background state and handle message navigates to a page.

this code snippet is worked --

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
     RemoteNotification? notification = message.notification;
     if (notification != null) {
       _handleMessage(message.dat,);
     }
   });
  1. when we hot restart from there --
RemoteMessage? message =
       await FirebaseMessaging.instance.getInitialMessage();
    this return old data  of consumed message (fromstep 1) .
    and is expected to work atlest 2 to 3 times , then discarded.

Please fix this , or give any suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions