android - Adding messages to HandlerThread's Queue from Ui Thread's onSensorChanged() method -
public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { if(seekbar.getid() == r.id.seekbar) { speed.settext(string.valueof(progress)); string outputdata = speed.gettext().tostring()+","+"hey"+","+"hell"+";"; if(streams.getoutputstream() != null && wthandler != null) { wthandler.sendmessage(wthandler.obtainmessage(9999, outputdata)); //wthandler handler handlerthread's looper } else { log.d("rtr", "handler of output stream null"); } }
i'm using handlerthread
send info via bluetooth.the code above transmits info when seekbar
changed , working.
when perform above transmission onsensorchanged()
method,it doesn't work.code below.
public void onsensorchanged(sensorevent event) { //to alter body of implemented methods utilize file | settings | file templates. if(event.sensor.gettype() == sensor.type_accelerometer) { float accxyz[] = event.values; float accx = accxyz[0]; float accy = accxyz[1]; float accz = accxyz[2]; x.settext(string.format("%.2f",accx)); y.settext(string.format("%.2f",accy)); z.settext(string.format("%.2f",accz)); //string outputdata = x.gettext().tostring()+","+speed.gettext().tostring()+";"; string outputdata = x.gettext().tostring()+";"; if(wthandler != null && wthandler.getoutputstream() != null) //add output stream null later { wthandler.sendmessagedelayed(wthandler.obtainmessage(9999,outputdata),10); log.d("rtr","added message queue"); } else if(wthandler == null) { log.d("rtr","worker thread handler not created yet"); } else { log.d("rtr","op stream null"); }
what might problem? suspect rate @ onsensorchanged() getting called.all above code running in ui thread , i'm adding messages handlerthread'
s looper
queue
here.
your thoughts please
this how changed rate @ messages beingness added queue , works fine now
public void onsensorchanged(sensorevent event) { //to alter body of implemented methods utilize file | settings | file templates. if(event.sensor.gettype() == sensor.type_accelerometer) { float accxyz[] = event.values; float accx = accxyz[0]; float accy = accxyz[1]; float accz = accxyz[2]; x.settext(string.format("%.2f",accx)); y.settext(string.format("%.2f",accy)); z.settext(string.format("%.2f",accz)); seek { //string outputdata = x.gettext().tostring()+","+speed.gettext().tostring()+";"; string outputdata = x.gettext().tostring()+","+speed.gettext().tostring()+";"; if( workerthread.getwthandler() != null && workerthread.getwthandler().getoutputstream() != null) //add output stream null later { if(system.currenttimemillis() - time > 50) { workerthread.getwthandler().sendmessage(workerthread.getwthandler().obtainmessage(9999, outputdata)); log.d("rtr","added message queue"); } } else if(workerthread.getwthandler() == null) { log.d("rtr","worker thread handler not created yet"); } else { log.d("rtr","op stream in handler null"); } }catch (exception e){ log.d("rtr","worker thread not created yet"); } time = system.currenttimemillis();
android
No comments:
Post a Comment