Shay Shay - 1 year ago 79
Android Question

Cordova - Push notification behavior while app is on background mode

I'm working on push notifications for Android and everything is working pretty good.

When app is open and active or closed, push notifications are working as expected.

When app is open but working on background - the push notification is received, but there are two possible outcomes here:

  1. The notification is pressed on the top taskbar - works as expected -> awakens the app from sleep mode and gets the notification.

  2. The app is being opened by the icon and not from the taskbar, the notification remains on the taskbar, and no events are being fired.

It would be expected that the notification will be removed when the app opens from on background, but it just stays there on top. And when clicked, the notification disappears and no data is received from it.

I wonder how you clever guys have solved it? I heard of the cordova background mode plugin, but I'm not sure whether it's the right solution to jump right into it. I guess I could get the data from the server instead, but what about removing the notification from the taskbar?

Much thanks for any help.

Answer Source

Sorry for the trouble, so I found out about this 'resume' event from cordova, that actually gets called whenever the app is coming from background mode.

That is just the functionality I was looking for. Maybe it'll help someone someday. ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download