android - How to unregister receiver attached to LocalBroadcastManager? -
how unregister receiver attached localbroadcastmanager?
i tried
unregisterreceiver(broadcastreceiver);
but gave me exception
java.lang.illegalargumentexception: receiver not registered:
this code
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); init(); locationmanager = (locationmanager) getsystemservice(location_service); localbroadcastmanager.getinstance(this).registerreceiver(broadcastreceivercancelpd, new intentfilter(pelicanapplication.identifiercancelpd)); localbroadcastmanager.getinstance(this).registerreceiver(breceiversignout, new intentfilter(pelicanapplication.identifiersignout)); localbroadcastmanager.getinstance(this).registerreceiver(breceivernearbydeliveries, new intentfilter(pelicanapplication.identifiernbd)); } @override protected void onstop() { super.onstop(); unregisterreceiver(broadcastreceivercancelpd); unregisterreceiver(breceiversignout); unregisterreceiver(breceivernearbydeliveries); }
calling unregisterreceiver()
calling method on current context, rather localbroadcastmanager. need call localbroadcastmanager.getinstance(this).unregisterreceiver();
.
Comments
Post a Comment