sports
sports

Reputation: 8147

Using GCM for transporting real data or just triggering events?

In a messaging application, like android's Gmail, you can refresh the inbox manually ("check for emails") and you can also receive emails via "push notifications"

Question:
Is it too inefficient if I use GCM only for triggering events that download the data, rather than sending the data?

Approach #1

  1. Server sends GCM message
  2. Android application receives message
  3. Android application now knows that it should check messages, ie:
    call the server's api: http://myserver/api/DownloadNewMessages

Approach #2

  1. Server sends GCM message, containing all data ("emails")
  2. Android application receives message.

The problem I see with Approach #2 is syncing and code repeating.

Syncing: when manually downloading new data, a verification is needed (is it really new data?)
Code repeating: there will be two ways of receiving data... (and two ways of sending, in server)

Upvotes: 0

Views: 42

Answers (1)

uDevel
uDevel

Reputation: 1891

I used Approach #1. It makes more sense and less error prone.

Push message is supposed to be small. It hints to the receiving client that it might be a good time to check for new message. I like the fact that it doesn't have to force the receiving client to take the data when it's not ready.

Also, it's much easier to maintain in long run when you change the data format in the future, because the GCM msg is still the same simple "Hey, there might be an update, go check if you want".

Upvotes: 1

Related Questions