16 July 2012

Can I check, if BroadcastReceiver is registered in Android?

No. API doesn't have this method :(.

Workaround solution.

If you worried,that is some bizzare cases yor 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  stackoverflow ) ,then I suggest surrond unregister with try/catch  IllegalArgumentException block


try {
   if (receiver != null) {
     this.unregisterReceiver(receiver);
   }
} catch (IllegalArgumentException e) {
    Log.i(TAG,"epicReciver is already unregistered");
    receiver = null;
}



No comments:

Post a Comment