PSIXO PSIXO - 4 months ago 19
Android Question

Receiver unregisterProblem

I am having the following problem in my app.
In on resume of my activity I register a broadcast receiver using this:

NetworkStateReceivernetworkStateReceiver = new NetworkStateReceiver(UIWrapperActivity.this);
filterConnectivity = new IntentFilter();
filterConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(networkStateReceiver, filterConnectivity);


And then in
onPause
I unregister it:

unregisterReceiver(networkStateReceiver);


In broadcast receiver in the same activity I catch
CONNECTIVITY_ACTION
and show a certain activity (Something like noConnection) switching to this activity does trigger
onPause()
of first activity so receiver is unregistered but than when I try to close the noConnection activity using
finish()
it's just reopened and won't go away.

Does anyone know what am I doing wrong and why is my broadcast receiver not unregistered?

Answer

I eventually found out what I was doing wrong so if someone gets this same error, here is the solution. I didn't finish the activity when I caught intent broadcast in the receiver so keep an eye out for that because if activity is still alive then it calls it's onResume() again and receiver gets re-registered.

Comments