Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity has leaked IntentReceiver that was originally registered here. Are you missing a call to unregisterReceiver()?

Tags:

android

01-16 16:52:42.211: E/ActivityThread(2529): Activity com.Civilcourage.CivilcurageSplash has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@405282e0 that was originally registered here. 

Are you missing a call to unregisterReceiver()?

What is the cause of the above error? How can it be avoided?

like image 932
Raj Avatar asked Jan 16 '13 11:01

Raj


2 Answers

Don't rely on onStop(), because:

Note that this method may never be called, in low memory situations where the system does not have enough memory to keep your activity's process running after its onPause() method is called

More on Activity life cycle here.

Unregister your receiver in onPause():

@Override
protected void onPause() {
    super.onPause();

    unregisterReceiver(yourReceiver);
}
like image 168
Melquiades Avatar answered Sep 20 '22 04:09

Melquiades


You need to unregister your receivers on stop of your activity:

@Override
protected void onStop()
{
    unregisterReceiver(yourReceiver);
    super.onStop();
}
like image 49
Nermeen Avatar answered Sep 20 '22 04:09

Nermeen