Thead:
1.有自己的消息队列:MessageQueue
Runnable:
1.public interface
2.Represents a command that can be executed
3.often used to run code in a different Thread
4.理解:它定义了一组操作,这组操作将被以消息的形式发给另一个Thread,是接收到该消息的Thread执行这组操作
5.常用实现形式:
new Runnable() {
public void run() {
//你的一组操作
}
}
Handler:
1.A Handler allows you to send and process Message
and Runnable objects associated with a thread's MessageQueue
.
2. Each Handler instance is associated with a single thread and that thread's message queue
3.it is bound to the thread / message queue of the thread that is creating it
4.常用方法:
post( Runnable r) |
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
mProgressStatus++;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();