0

I have integrated my application with the GCM. Setup the third party server which checks whether an update needed for a device, if yes, it sends the GCM as a tickle telling the mobile application to contact the server for the fresh data.

My android application has authentication module with logon/logoff actions. And I only intend the server data synch (and so as the GCM messages) as long as user's current session is active.

But, as the tutorial suggests, the Android application on an device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives.

My question is, how do I prevent the GCM messages when user is logged off or the application is shutdown?

Which one of the following seems better? can you suggest any other approach?

Option A:

My android application to register for the GCM once the user is successfully logged on and un-register from the GCM once the user is logged off. This will enforce my third party server to only send the GCM messages when the registration id is available. But is the register/un-register so frequently is a recommended practice?

Option B:

Let the android application receive the messages even during logged off or shutdown state, but the application does not react on them (i.e. just ignore them). Is this a recommended practice? Would it cost any penalty in terms of performance? Would the user notice un-necessary (annoying) wakeups of the android application?

Any help would be appreciated.

4

1 回答 1

1

根据我的建议,第二个是更好的选择,您可以执行从服务器收到的任何推送消息,将其更新到首选项文件(仅最后一个或 imp 一个),并在用户登录时通知他/她。

于 2013-01-03T19:57:53.907 回答