Today I encountered this error: has leaked intentreceiver ... that is originally registerd here. Is you missing a call to Unregisterreceiver
:
The Chinese meaning of this error is that it has overflowed the intentreceiver, did you forget to call the method of canceling the broadcast?
Reason for the problem:
The reason is overflow intentreceiver, because there is receiver has not been unregister after the register, repeated several times after causing intentreceiver leakage
But I actually have to call Unregisterreceiver (Batteryreceiver), then why this problem still occurs
Workaround:
In order to avoid this problem, register the broadcast and write off the broadcast to appear in pairs , but at the same time in order to avoid the problem of NULL pointers, we'd better add a flag-bit flag
/** * Flag bit, whether Broadcasereceiver open, default to False */boolean Flag=false;
Change flag to True when registering a broadcast
/** * Register broadcast */private void Registerreceiver () {flag=true;intentfilter filter = new Intentfilter (); Filter.addaction (Intent . action_battery_changed); batteryreceiver=new batteryreceiver (); Registerreceiver (batteryreceiver, filter);}
Before cancelling the broadcast, first determine if flag is true (that is, whether the broadcast has been registered), or if true, to unregister the broadcast
@Overridepublic void OnPause () {if (flag) {flag=false;unregisterreceiver (batteryreceiver);} Super.onpause ();}
The reason to add flag is to avoid not registering the broadcast, but to cancel the broadcast, so there will be a null pointer
Reprint please indicate the source, thank http://blog.csdn.net/harryweasley/article/details/45073065
Has leaked intentreceiver ... that is originally registerd here. Is you missing a call to unregister