Mobile Integration Plug-in provides a unified support for collapse keys for both APNS and GCM. This feature allows a key known as Collapse Key to be attached to the notifications. If multiple notifications arrive in a sequence with same collapse key, over a period of time, the Mobile Integration plug-in collapses these notifications at its end. This means that all older notifications are discarded and only the latest notification are stored on the Mi Service. When a device comes online and pulls the notifications from the server, it receives only the latest notification among the notifications bearing the same collapse key. However, if the collapse key is not set, both the new and old messages are stored for the future delivery.
The best scenario suited is, when the device is offline and does not receive older notifications already dispatched to its platform notification service. In case the device is online, then it may still receive notifications that were already dispatched from its platform notification service. Collapse key facilitates collapsing of the waiting and undelivered notifications.
A perfect example for this would be about sending live cricket score updates to the users. If the user didn't receive the previous score updates then it is not necessary to store all them. The user would be interested only in the latest updates.
When a user sends a notification to the mobile application, the Mi Service stores the notification and pushes it to APNS and/or GCM for delivery. Mi Service maintains a notifications queue for each device from which the device can pull the messages addressed to it. Hence, if there are multiple notifications addressed to a particular device, then these notifications get queued up in its notifications queue in the sequence they are received.
The collapse key collapses only the notifications bearing the same collapse key. If a user sends 10 notifications with the same collapse key (for example, "SCORE") and 2 notifications without any collapse key and they are not received by the device as the device was offline. Then when the device is back online, it will receive total 3 ( 1+2 ) notifications, provided none of the 3 notifications expire in the mean time.
GCM supports collapse key out of the box while APNS has no concept of collapse keys. APNS does not require collapse notifications because it stores only a single notification always (which is always the latest) per device. APNS discards the older notifications automatically. However, GCM can store up to 100 messages per device and attempts to deliver them to the device when it is online or connected. Hence, GCM needs collapse keys to filter irrelevent notifications. Now, GCM allows a maximum of 4 different collapse keys per device at a specified time. You can have more than 4 collapse keys but not at the same time. For details refer to http://developer.android.com/google/gcm/adv.html.