Push notification not working when app is not running Android


Hi people,

I am facing very blocking problem which is concerning push notification on Android (I have not tested it yet on IOS). Push notifications are working pretty well when we are running the app (in foreground and background). But if the app is not started at all there is no way to receive anything. I have to start back the app to receive delayed notifications… Is there anything wrong ?

Thank you.


Yeah most tutorials on the web are describing the pushservice for “coldstart” wrong.

if you restart your app -> you have to first reregister the device to connect the onNotificationCallback correctly again.
If not the coldstart will destroy your push notification handling, because if you restart your app the pushplugin does not know anything about your earlier connected notification callback.

The problem is, that the pushplugin fires outside of the ionic/angular context -> that means, if you are in coldstart your app is maybe not ready when the event fires.

For that i created some custom javascript events which i am firing when the app is ready (in a controller) or if the plugin gets a notification.

In my controller i check if there is a apn/gcm id on the scope -> if not i know it was a coldstart -> unregister and register the device.

Greets, bengtler


For what it is worth, I don’t agree with @bengtler, I don’t need any of what he is talking about and it is running well here.
My code is based on the tutorial by Michael Mendelson at http://intown.biz/2014/04/11/android-notifications/


Yeah but the tutorial does exactly the same…

listens on device ready -> if ready reregister your device ;).
In my case only logged in users are able to get push notifications, so i have to listen on this event somewhere else.

I had only the problem, after coldstart i get push notifications, but the handling was not correct. So i build something own.
If it works perfectly for you it is okay.
I needed to use unregister for android, because in somecases i get different ids from gcm for the same device (after reinstalling the app and so on) -> so the device gets multiple identical push notifications. To avoid that i added unregister, register and my special event, that checks if appready and a new message is there -> i only add identical messages once and trigger my event.

So it is working for me… maybe in a little bit triggy way, but it works in ALL cases ;).

greets, bengtler


I am not sure we are talking the same thing. What I mean is when your application is not running anymore, how do you handle notifications ? I am sure GCMIntentService is correctly handling the notifications because it’s a background service. But what about the ability to show it to the user ?


When your app is not running, Android will display the notification in the status bar, without your app knowing it.
It is only when the user clicks the notification that your app will be started, this is the “coldstart” type of event.


That is the thing i try to explain.

You close your app, after you have registered the push service for your app.
Now you should get notification and if you click on it your app starts.

In my case i want to redirect to the message detail view. in all my tries this does not work after coldstart. And if my app is now open and i get another notification my handling does not work either in foreground or background, because the push plugin lost my onnotification callback.

So after the pushplugin goes in the coldstart callback 1 time, but your app is not ready to route (that was so in my case). Thats why i need to reregister the app to put the callback on the pushplugin.


Well I see,

Is the “message” and “msgcnt” fields mandatory inside the data payload to get notification in background ? Because I made some modification on GCMIntentService but it seems that the "extras.putBoolean("foreground", false)" is quite important for routing message. Is that the case ?

Thank you.


Yep it is important ;).

because if foreground is true there is another handling then it is false.
There are three states:

  • foreground -> route directly
  • background -> route directly
  • coldstart -> wait until app is ready (controller is loaded, states and services are initialized)


No, msgcnt for sure is always optional.


oh i do not read “msgcnt” there is jesperwe absolutely right.

MSGCNT sets only a number in the statusbar.

I only answered the second question… sorry


Thank you guys, this now clear for me.

Happy new year 2015 to you and keep ionic up :slight_smile: !!


Hi guys,
I am stuck with the same problem.when i close my app completely then no push notification recieved. I am using ionic push. If anyone know about the solution plz help thanks.



Only a question…changes in GCMIntentService …how i must do to incorportate them to the apk?

I have changed this file, but when i run “ionic build” these changes are not in the apk file.


Hai bengtler,

can u share the code snippet …


woooooaah… 1 year later ^^… sry but i do not have access to the project anymore


hey bengtler ,

Than you for your suggestion. I got it when app in cold start also. But I am unable to get my notification data when i am not tapping on notification status bar. Can u help me out this??.