I created a Push Notification Server (PNS) by using Google Cloud Messaging (GCM). With this architecture, my server has to know the token associated to a user in order to send him push notifications.
I extended the class InstanceIDListenerService
which is correctly notified when a token has been refreshed (I tested it with adb). When its method onTokenRefresh()
is called I take the new token and, so far, all is ok.
My problem is the following: what if I fail to send this new token to my server? (a network error, a lack of connection, a sudden device shutdown, or something else...). Do I have to store somewhere (preferences?) that server does not know my new token and retry when possible? Is there a way to let the OS to perform this operation?