Registration ID best practices

508 views
Skip to first unread message

cmolson

unread,
Oct 15, 2010, 1:32:57 PM10/15/10
to android-c2dm
What is the best way to manage a registration ID, examples:

If a single device registers multiple times for a registration id, and
never calls unregister, it could potentially have multiple valid (can
send a message using it) registration ids.

Does your app only ever have to register once for a regID and then no
matter what state it is in, it will renew it (receive a new
registration intent) when the OS/google tells it to?

Currently I have my app register for an ID, then save it to persistent
storage. My question is, then when I start the app for the second time
I just read the key from memory. What if the user upgrades their app?
do i need to re-register.

I originally thought no matter how many times i register, one device
would only have 1 registration ID (google would invalidate the
previous one or something). It seems like a device can have multiple
valid registration ids.

I'm kind of confused right now... Thanks!

Costin Manolache

unread,
Oct 15, 2010, 2:10:14 PM10/15/10
to androi...@googlegroups.com
On Fri, Oct 15, 2010 at 10:32 AM, cmolson <cmol...@gmail.com> wrote:
What is the best way to manage a registration ID, examples:

If a single device registers multiple times for a registration id, and
never calls unregister, it could potentially have multiple valid (can
send a message using it) registration ids.

You should use the last registration id. You should also call unregister, but 
nothing very wrong will happen if you don't. Note that if you call 'unregister' - all
keys for your app will stop working, not only the last one - unregister will stop
accepting messages for this device/application. 

Right now older registration IDs may happen to work - but it may change 
in future.



Does your app only ever have to register once for a regID and then no
matter what state it is in, it will renew it (receive a new
registration intent) when the OS/google tells it to?

Yes. The 'renew' is not a frequent event, only if we make backward incompatible changes
or key changes - but you must be able to handle this.
 

Currently I have my app register for an ID, then save it to persistent
storage. My question is, then when I start the app for the second time
I just read the key from memory. What if the user upgrades their app?
do i need to re-register.

No, the registration key is associated with the application id, you don't need
to re-register on upgrade. 


 

I originally thought no matter how many times i register, one device
would only have 1 registration ID (google would invalidate the
previous one or something). It seems like a device can have multiple
valid registration ids.

It's either a bug or feature, but please don't rely on this :-)

 

I'm kind of confused right now... Thanks!

Costin

cmolson

unread,
Oct 15, 2010, 10:14:11 PM10/15/10
to android-c2dm
That clears up a lot, thank you for taking the time to help me out!

Maybe I should put what I am doing in a better context:
My app communicates with several servers. It may log in to server A on
monday, then use server B on tuesday. It does not have a sense of what
server it is connected to, so when it first connects (and on
subsequent requests to that server) I send the registration id to the
server.

Currently it could happen that server A sends a c2dm to the client,
while it is logged in to server B. In this case it looks to the user
like a false message, as it doesn't know the push came from another
server, it assumes the currenty connexted server sent it. This is OK
for now and could be solved by adding server info to the push message.

The only foggy point for me is - am I guaranteed that once my app
registers once, even if I uninstall and reinstall my app I don't have
to re-register? Or what if I update my app via market place.

Since I am commuunicating with multiple servers I need to store the
registration I'd on the client - how do I know that this is has not
become invalid? I do update this whenever I receive a registration
intent, but I'm worried that this I'd will become invalid without me
knowing.

Thanks again, maybe i am missing something fundamental about
this... :)
On Oct 15, 2:10 pm, Costin Manolache <cos...@gmail.com> wrote:

Costin Manolache

unread,
Oct 15, 2010, 11:28:20 PM10/15/10
to androi...@googlegroups.com
On Fri, Oct 15, 2010 at 7:14 PM, cmolson <cmol...@gmail.com> wrote:
That clears up a lot, thank you for taking the time to help me out!

Maybe I should put what I am doing in a better context:
My app communicates with several servers. It may log in to server A on
monday, then use server B on tuesday. It does not have a sense of what
server it is connected to, so when it first connects (and on
subsequent requests to that server) I send the registration id to the
server.

Currently it could happen that server A sends a c2dm to the client,
while it is logged in to server B. In this case it looks to the user
like a false message, as it doesn't know the push came from another
server, it assumes the currenty connexted server sent it. This is OK
for now and could be solved by adding server info to the push message.

Yes, from C2DM point of view there is one application and one registration ID.
 

The only foggy point for me is - am I guaranteed that once my app
registers once, even if I uninstall and reinstall my app I don't have
to re-register? Or what if I update my app via market place.

Uninstall is a bit more complicated - if the device receives a message and it 
detects that the app is not installed it'll send an automatic 'unregister', so the 
phone is not woke up again. In future we may unregister immediately on uninstall - 
so don't assume that the unregister will be delayed to the first message, it's just 
the current behavior. 

Update should be safe. 

 

Since I am commuunicating with multiple servers I need to store the
registration I'd on the client - how do I know that this is has not
become invalid? I do update this whenever I receive a registration
intent, but I'm worried that this I'd will become invalid without me
knowing.

The registration will be valid until google sends you a new one, and it may 
even be valid for a very short interval after ( to account for delays in sending the new 
registration to the 3rd party server ).

Are the multiple servers independent ? I assume all are under your control, since they all need
 the auth token to send messages. If this is the case - it may be better to not have the 
phone send to all servers, bandwidth is more expensive on the phone. There are various 
ways to replicate the registration among servers.

Costin
Reply all
Reply to author
Forward
0 new messages