Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Android double on('notification') fired #828

Closed
dylanvdmerwe opened this issue Apr 22, 2016 · 10 comments
Closed

Android double on('notification') fired #828

dylanvdmerwe opened this issue Apr 22, 2016 · 10 comments

Comments

@dylanvdmerwe
Copy link

dylanvdmerwe commented Apr 22, 2016

Actual Behaviour

When an Android app is in the background (in memory not killed) and a push message with content-available: 1 is received the following happens:

  1. Push message is received on the phone.
  2. The on('notification') event fires in the background (coldstart: undefined, foreground: false).
  3. User presses the push notification.
  4. The on('notification') event fires again as the app opens. (coldstart: false, foreground: false).

Expected Behaviour

I do not expect the notification event to be fired twice. Or if it is going to be fired twice (once to process the data when it is received and another time if the user presses the notification) then this needs to be consistently implemented across iOS as well.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 6.0.1

What device vendor (e.g. Samsung, HTC, Sony...)

Tested on Nexus 5.

Cordova CLI version and cordova platform version

Cordova CLI: 6.1.1
Ionic Framework Version: 2.0.0-beta.6
Ionic CLI Version: 2.0.0-beta.24
Ionic App Lib Version: 2.0.0-beta.14
OS:
Node Version: v5.10.1
android 5.1.1
ios 4.1.1

Plugin version

1.6.2

Sample Code that illustrates the problem

See my repo that I have put together for testing the various scenarios.

@Radu80
Copy link

Radu80 commented Apr 22, 2016

Hi,
I also have the same problem

@macdonst
Copy link
Member

@dylanvdmerwe three for three on great issue descriptions but in this case it is by design. If you send a notification with content-available: 1 it will fire the event in the background. If the notification also includes a title and message then it will be shown in the notification shader. Once you click on the notification the event will be fired again.

I've told people multiple times if they don't want this behaviour they should do one of the following things:

  1. don't include title/message in the push so it doesn't show up in the shader.
  2. send two pushes, one to be processed in the background the other to show up in the shade.
  3. include a unique ID in your push so you can check to see if you've already processed this event.

Perhaps we need better docs?

@dylanvdmerwe
Copy link
Author

Those suggestions make perfect sense. I think more documentation on this would be extremely beneficial.

@jordidiaz
Copy link

@macdonst You made my day! I have implemented the third option and works fine. Thank you!

@macdonst macdonst added this to the Release 1.7.0 milestone May 26, 2016
@macdonst
Copy link
Member

macdonst commented Jun 2, 2016

push-flowchart

@macdonst
Copy link
Member

macdonst commented Jun 2, 2016

@macdonst macdonst closed this as completed Jun 2, 2016
@checo06
Copy link

checo06 commented Jul 26, 2016

@macdonst for avoiding the 'notification' fire twice when "content-available" is set to 1, im checking that if coldstart and foreground flags both are set to false it cames from a user tap on the notification center, so i skip this event. Do you think this is a valid way (and possibly another strategy) to solve the avoiding twice firing thing?

if( !data.additionalData.coldstart && !data.additionalData.foreground ){
//set a flag to skip notification processing
}

@checo06
Copy link

checo06 commented Jul 29, 2016

My previous comment was wrong.

I finally also used the strategy "3 include a unique ID" and worked good. In my case i checked with the previous idPushNotification processed (i save the last idPushNotification on localStorage )

@jakute
Copy link

jakute commented Jan 13, 2018

Hello @checo06 can you please help me with the logic of how to see if the Id already exist?, because i have the issue that my notifications duplicates.
thanks in advance

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

6 participants