Search code examples
androidandroid-c2dmgoogle-cloud-messaging

Leaked IntentReceiver in Google Cloud Messaging


I have implemented GCM in my app and I am using GSMRegistrar as suggested here. No I am getting an error in logcat

7-02 23:35:15.830: E/ActivityThread(10442): Activity com.abc.xyz.mnp has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@44f8fb68 that was originally registered here. Are you missing a call to unregisterReceiver()?

What I can understand from this and looking at the code for GSMRegistrar is I need to to call GSMRegistrar.onDestroy(this) but I could not understand where should I call this? Calling in onDestroy() of activity mnp causes it to stop retrying for GSM Registartion


Solution

  • You may use the application context, instead of the activity context. That way the backoff mechanism is not restricted by the activity life cycle.