当前位置: 动力学知识库 > 问答 > 编程问答 >

How can I process multiple push notifications in Android, before doing action

问题描述:

In my chat app I send push notifications for new messages. Normally when app receives push it will send request to server to fetch info for new messages. My problem rise when user is offline for long time, and lot of pushes accumulated for that user. Then when he comes back online he receives all pushes at once.

So when many pushes come my app starts to make request for each push.

How can I process all pushes first and then make single request to server.

Edit 1

To fetch new messages from server I build request where I put last message id I have locally. Then server will return me all new messages after that message id.

This is my retrofit code.

public interface GroupChatFromDateInterface {

@GET("/groups/{groupId}/show_messages.json")

List<Message> groupMessages(@Path("groupId") int groupId,

@Query("auth_token") String token,

@Query("after_message_id") int messageId);

}

网友答案:

The easiest way to handle this issue is to use a collapse_key in the GCM message you send.

If all your GCM messages have the same collapse_key, when a device is offline the GCM server would store only one message for that collapse_key.

When the device is back online, it will receive just one GCM message, and your app will make a single request to your server.

分享给朋友:
您可能感兴趣的文章:
随机阅读: