how to check if a broadcast receiver is registered in android?
how to check if a broadcast receiver is registered in android?
No. API doesn't have this method:
Workaround solution.
If you worried, that is some bizarre cases your
receiver can be magically unregistered or you suffer from annoying bug with
view/rotation crashes (Appear in Android 2.1-2.3.7)
http://code.google.com/p/android/issues/detail?id=6191 (which is described in
almost all forums for android developers or websites like stack overflow), then
I suggest surround unregister with try/catch IllegalArgumentException block
try { if (broadcastReceiver != null) { this.unregisterReceiver(broadcastReceiver); } } catch (Exception e) { Log.i("", "broadcastReceiver is already unregistered"); broadcastReceiver = null; }
Comments
Post a Comment