Skip to main content

Solucionar error has leaked IntentReceiver en Android

Tengo una clase extendida de BroadcastReceiver en MainActivity.java lanzo el listener

registerReceiver(
        new ConnectivityChangeReceiver(),
        new IntentFilter(
                ConnectivityManager.CONNECTIVITY_ACTION));

Me encuentro que cuando salgo de la app me muestra el siguiente error en el log:

E/ActivityThread: Activity com.webserveis.app.myconnection.MainActivity has leaked IntentReceiver com.webserveis.app.myconnection.ConnectivityChangeReceiver@32ad932e that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Activity com.webserveis.app.myconnection.MainActivity has leaked IntentReceiver com.webserveis.app.myconnection.ConnectivityChangeReceiver@32ad932e that was originally registered here. Are you missing a call to unregisterReceiver()?

that was originally registered here. Are you missing a call to unregisterReceiver()

En onStop() me gustaria desregistrar el listener, pero no ser como implementarlo

Codelaby
  • 11.2k
  • 15
  • 73
  • 154