3

I have some apps which are using gcm notification. They work fine but there is an issue here: if I don't open one of them for almost a long time (like 2 monthes or more) it will not receive notifications anymore.

Acctually, I experienced this behaviour with stackoverflow app too. Can anyone explain what is the reason and how to avoid it?

Akram
  • 2,158
  • 1
  • 17
  • 24

2 Answers2

1

Usually a gcm notication has a lifespan of 4 weeks after that it google stops broadcasting it. But in your case, apps generally have wake-timers to allow them to wake up periodically and try to receive notifications even without being opened. If you are loosing notifications on some of your apps, then check if you have a battery-saving app e.g Greenify or others that are effectively blocking notifications wake ups for your apps. If not then may be your ROM has a battery saving feature that blocks this wake-ups e.t.c Certain conditions may also trigger wake-up in apps such as a WiFi connection or Data switched on.

Bmbariah
  • 687
  • 2
  • 10
  • 22
  • Thanks for your answer, I've tested on some different phones but none of them had battery saving enabled. Also about the 4 week life time of notifications, I mean that these apps will not receive any notifications at all after some time of inactivity for example if I send a notifiacation right now, it will not receive it not now and not anytime later in the future despite that it is connecected to internet and other apps have no problem in receiving notifications. If I open this sample app once, it will receive notifications from then on. About "wake-timers" can you explain it with some code? – Akram Jan 01 '17 at 12:57
1

It is recommended here to put a service that runs continuously in background. Be noted that IntentService stops itself when it runs out of work.

Also, according to this thread:

If a user force-stops your app from Settings, your code will never ever run again, until something manually runs one of your components, typically the user manually launching an activity (as of Android 3.1). Hence, if the user force-stops your app from Settings, you will not receive GCM messages on newer devices/emulators.

And as @Bmbariah stated, an Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions. You may check this WakefulBroadcastReceiver service that lets you manage the life cycle of a background task.

The docs only say "Wake up" which to me implies an app is "sleeping" or in the background. But when you force close an app it has no running process to "wake up", it needs to be started.

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59