The root of your problem is located here:
unregisterReceiver(batteryNotifyReceiver);
If the receiver was already unregistered (probably in the code that you didn’t include in this post) or was not registered, then call to unregisterReceiver
throws IllegalArgumentException
. In your case you need to just put special try/catch for this exception and ignore it (assuming you can’t or don’t want to control number of times you call unregisterReceiver
on the same recevier).