Android - registerReceiver / multiple action -


i have question registerreceiver , addaction.

let's have servide, runs in activity (via start button). service register receiver via registerreceiver. there in onstartcommand() method of service :

final intentfilter filter1 = new intentfilter(); filter1.addaction(action_1); // action defined in code this.br_receiver = new mybroadcastreceiver();  // class defined in code this.registerreceiver(this.br_receiver, filter1); return (start_sticky); 

now, let's have 3 different actions , 3 checkboxes (one each action). when press button, starts service checks actions has add via addaction method(). of course there stop button.

my question : when use unregisterreceiver() method how can stop handling action want (i know ones checkbox checked before clicking onto stop button) ?

i not sure clear going explain in different way : know 1 solution add actions (addaction) when start service , then, in onreceive method(), use 3 boolean in order know action take care of. think solution crappy.

sholuld use different intentfilter, 1 each action ? if yes, how ?

if have anwser or advice, you're welcome !

thanks.

my question : when use unregisterreceiver() method how can stop handling action want (i know ones checkbox checked before clicking onto stop button) ?

option #1: register 3 receivers, 1 per action, , unregister 1 action user unchecks.

option #2: register actions user has checked, , when user changes checked/unchecked state of checkbox, unregister , re-register receiver.


Comments