FirebasePushNotificationPlugin icon indicating copy to clipboard operation
FirebasePushNotificationPlugin copied to clipboard

OnNotificationOpened runs more than once

Open jpolocosme opened this issue 5 years ago • 7 comments

Hello, I receive notifications well, but I have noticed that, for example, if I install the application for the first time on the device, the method: OnNotificationOpened is executed 2 times, and when the application is already installed and I only update, it executes more than 3 times, this is annoying because I give it parameters so that through this method it can go to the view that I want, does it mean that this method makes it go to a view 3 times, has this happened to someone?

` CrossFirebasePushNotification.Current.OnNotificationOpened += async (s, p) => { if (data.Key=="moredata") { tag = (string)data.Value; } ........here I recover the parameters......................

await Navigation.PushAsync(new ListRequest(), false); } `

jpolocosme avatar Nov 23 '20 20:11 jpolocosme

I can confirm I have this same issue. OnNotificationOpened gets executed twice

Tarekka avatar Dec 08 '20 17:12 Tarekka

OnNotificationOpen is executed the number of times per notification, it increases each time by 1, I have a splashscreen and I use the sample example.

any solution? @rdelrosario @tarekka @jpolocosme

if you have splashscreen with this code it solves:

  var mainIntent = new Intent (Application.Context, typeof (MainActivity));
    if (Intent.Extras! = null)
    {
     mainIntent.PutExtras (Intent.Extras);
    }
    mainIntent.SetFlags (ActivityFlags.SingleTop | ActivityFlags.ClearTop);

angelru avatar Dec 13 '20 20:12 angelru

@jpolocosme @angelru Subscribe to the events in the OnStart() event of App.xaml.cs instead of the constructor. I was doing it in the constructor and after moving it to OnStart it worked.

Tarekka avatar Dec 15 '20 17:12 Tarekka

@Tarekka @jpolocosme

I can confirm it works as expected, thanks :)

angelru avatar Dec 16 '20 08:12 angelru

This does not work for me.

OnStart() still getting triggered after tapping on the notification box so I have to unregister and register on the events

jaysonragasa avatar Jan 21 '21 22:01 jaysonragasa

I ended up making a separate class and putting all the plugin events there and then checking if my class is null or not

 private static FirebaseConfService firebaseConfService;

        public static void InitFirebaseConf()
        {
            if (firebaseConfService is null)
            {
                firebaseConfService = new FirebaseConfService();
            }
        }

angelru avatar Jan 23 '21 16:01 angelru

I just add this:

        static bool firebaseInitialized = false;
        ...

            if (firebaseInitialized )
                return;

            firebaseInitialized = true;

            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
 
            ...

rubenc57 avatar Apr 18 '21 17:04 rubenc57