I recently reorganized an old project and found that a certain part no longer wants to work properly no matter what I do. Essentially, I have an Activity with a TextView. This view is updated at regular intervals from a thread called in the same class. A pause is performed using Thread.sleep, and a handler is used to start updating the user interface. The fact is that now I either get a CalledFromWrongThreadException, saying that I can not manipulate the view from another thread, a long pause, followed by all the text that got into the view right away, or it seems to fire immediately and do not sleep at all. I previously did it like this (relevant parts were included):
public class Updated extends Activity implements Runnable {
private TextView textView;
private String text;
private Handler handle = new Handler(){
@Override
public void handleMessage(Message msg){
textView.append(text);
}
};
new Thread(this).start();
}
public void run(){
text = "Blah blah";
handle.sendEmtpyMessage(0);
try {
Thread.sleep(1500l);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
, , . , , Handler. , .obj, String, TextView. . Handler , , .post(Runnable() {}); , . Handlers Threads Java/Android, .