An infinite loop in the ui thread is probably not a good idea. setText schedule the operation of drawing, placing in the queue of threads ui. Unfortunately, the same thread is busy with the loop. You can use the internal TextView handler to publish Runnable to the ui thread queue. For example.
private Runnable mRunnable = new Runnable() { @Override public void run() { if (!flag) { outCPU.removeCallbacks(this); return; } outCPU.setText(getCpuInfo()); outCPU.postDelayed(this, 200); } };
and instead of your while loop you just do
outCPU.post(mRunnable);
Blackbelt
source share