I have GCM completely working. My question is when I exit my app with the android BACK key I see the onDestroy() called and to avoid leaks I unregistered the receiver for gcm so it’s onUnregister() is called. But I want to be able to register gcm once at power up (boot completed?) and then be able to get notifications any time. I know I will need to still handle when google may refresh the reg intent. But I’m not clear if I need to make a new service to register gcm in in its onCreate()? Right now I register gcm in the main activity’s onCreate().
Thanks for any help!!
Justin
Without looking at your code it’s a bit hard to tell, but you should not be unregistering from GCM every time you leave the app. A typical GCM App life-cycle (if you are using the GCM jar) would be the following:
Number 4 would probably be unregistered from GCM when they turned off a preference to unregister from receiving notifications.
Take a look at Google’s Client sample DemoActivity: http://code.google.com/p/gcm/source/browse/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/DemoActivity.java
Notice that they do not unregistered from GCM. If you follow their sample you will receive notifications after the device powers up without having to do anything else yourself.