Thread

标签: Thread

安卓子线程访问UI线程的四种方法

1.第一种 Handler机制:通过Handler+Message实现通信 Message msg = new Message(); msg.what = 0x1234; msg.obj = null; handler2.sendMessage(msg); 2.第二种 Activity.runOnUiThread(runnable); runOnUiThread(new Runnable() { public void run() { tv.setText("执行完成"); } }); 3.第三种 View.post(runnable); View.post(Runnable)方法。在post(Runnable action)方法里,View获得当前线程(即UI线程)的Handler,然后将action对象post到Handler里。在Handler里,

阅读全文...