There is a code that in the stream receives data from the controller:
Handler mHandler = new Handler(); private void tvAppend(TextView tv, CharSequence text) { final TextView ftv = tv; final CharSequence ftext = text; mHandler.post(new Runnable() { @Override public void run() { ftv.append(ftext); } }); } How can I stuff a team in this thread that should work forever in a stream with a delay of 100 milliseconds
bytesToSend = addCRC(new byte[]{1, 0x3, 0, 0 ,0, 0}); mPhysicaloid.write(bytesToSend, bytesToSend.length); All code can be seen https://github.com/ksksue/PhysicaloidLibrary/blob/master/SampleProjects/tutorial5/src/com/physicaloid/tutorial5/Tutorial5Activity.java
UPD: If I correctly understood the answer @ saidolim-djuraev, then my code now should be like this:
Handler mHandler = new Handler(); private void tvAppend(TextView tv, CharSequence text) { final TextView ftv = tv; final CharSequence ftext = text; mHandler.post(new Runnable() { @Override public void run() { ftv.append(ftext); while (true) { bytesToSend = addCRC(new byte[]{1, 0x3, 0, 0, 0, 0}); mPhysicaloid.write(bytesToSend, bytesToSend.length); try { Thread.sleep(100); } catch (Exception ex) { } } } }); } But how then to start this thread in one method, and stop the flow when executing another method?
Но как тогда этот поток запустить в одном методе, а остановить поток при выполнении другого метода ?this is another question - Saidolim