It should be called inside onDestory() method of the activity that you started the GCM registration.
Keep in mind an activity may not be destroyed, even though another activity is launched on top of it. So your registration could still be retried in the background. If the registration activity is destroyed, then your GCMBroadcastReceiver class won't be there to handle the response anyway.
Update: After looking at the GCM library source code more carefully, here's what I've observed:
- The GCM library uses the activity context to register a receiver, for the purpose of retrying registration if it fails, it will use a backoff mechanism to retry.
- You should call GCMRegistrar.onDestroy() on your activity's onDestroy() method, it's a good Android practice to unregister a receiver before activity is destroyed.
- Because of #2, it means that your app won't attempt to re-register, if the activity that calls GCMRegistrar.register is destroyed. The user has to go back to this activity for the registration process to kick off again.
- If you don't want behavior #3, you may have to implement your own GCM registration and retry mechanism. For example, if the retry mechanism is done in a separate background thread, then it could keep on trying even though the activity is destroyed, as long as the application is running.
I think #3 is acceptable, as it's very rare that the GCM server will reject the registration with 'SERVICE_NOT_AVAILABLE' error. And as long as your user runs your app a few times, sooner or later their device will have successful registration.