Search code examples
androidandroid-c2dm

How to receive multi c2dm notifications?


I'm using C2DM to send notification for my android App and it is working fine. But i am able to get only one notification at a time. so that while receiving the notification, it replaces previously received notification.

So how to receive multiple C2DM notification, like receiving normal SMS?


Solution

  • Give the messages different collapse_keys. Here's an excerpt from the official docs:

    An arbitrary string that is used to collapse a group of like messages when the device is offline, so that only the last message gets sent to the client. This is intended to avoid sending too many messages to the phone when it comes back online. Note that since there is no guarantee of the order in which messages get sent, the "last" message may not actually be the last message sent by the application server. Required.

    On a side note; you are not supposed to use the push messages too frequently:

    Are you sending C2DM messages too frequently? If you need to communicate with your application frequently over a short period of time, C2DM is probably not the best solution. Instead, consider implemeting XMPP or your own protocol to exchange messages, and use C2DM only to send the initial notification.