GCM Message is not sent when the app is not open?

后端 未结 2 1759
闹比i
闹比i 2021-01-28 03:44

Recently I implement the GCM on my app. I followed the tutorial code at this website

http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifi

相关标签:
2条回答
  • 2021-01-28 04:42

    WhatsApp doesn't rely entirely on GCM (I'm not sure if it relies on GCM at all). If you open your Android device's Settings and go to Applications and then Running services (the menus may be a little different if you are using a different Android version than I'm using, which is 2.3.6), you'll see there's a WhatsApp service running in the background (assuming you have WhatsApp installed). If you stop that service, you would stop receiving messages from WhatsApp until you launch that app again.

    Your app can accept GCM broadcasts only as long as you don't kill it explicitly. Once you kill it, it won't receive any broadcasts until the next time you launch it (according to what I read, that has been the case since Android 3.x). If, however, you move your app to the background (for example by launching another app or hitting the back button until you move to the home screen or to another app), your app would still get messages from GCM.

    0 讨论(0)
  • 2021-01-28 04:47

    The GCM engine will try to deliver a message once it detects you've established a connection to them. I guess that when you kill your app, so is killed the open socket waiting to get messages and they won't try to deliver the message again.

    When you open up the app again, all the pending messages are delivered as the GCM engine will try to deliver all of them once it detects you've established a connection to them, that's why you get them all at the same time.

    0 讨论(0)
提交回复
热议问题