java - How to stop a Thread running a Handler? -



java - How to stop a Thread running a Handler? -

i have thread within service listens handler instructions , writes byte[] commands bluetooth stream:

class btoutgoingthread extends thread { private static final string inner_tag = "btoutgoingthread"; public void run() { log.e("service: btoutgoingthread","starting"); this.setname(inner_tag); looper.prepare(); mmyservicehandler = new handler() { public void handlemessage(message msg) { // handle messages... switch(msg.what) { case 1: // message write(reset); break; case 2: // other message write(motreset); break; } } }; log.e("outgoing thread","active"); if(stopoutgoing){ // set true in service ondestroy() log.e("service: btoutgoingthread","terminated"); for(int = 0; < 15; i++){ mmyservicehandler.removemessages(i); // remove messages } mmyservicehandler.getlooper().quit(); // end looper return; } looper.loop(); } public void write(byte[] bytes) { seek { (int = 0; < 20; i++) // 20 rounds, rapid, fire! { mmoutstream.write(bytes); // bang } } grab (ioexception e) { } } }

it works until seek stop thread. set stopoutgoing true, doesn’t anything. i’ve tried putting return; command executed handler, as useless.

i don’t why looper doesn’t seem loop. should spamming logcat , creating infinite new handlers, doesn’t happen.

i’d understand why looper working way is, @ point i’d settle technique end thread. help appreciated.

java android multithreading handler

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -