-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandler.java
More file actions
45 lines (38 loc) · 1.07 KB
/
Copy pathHandler.java
File metadata and controls
45 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* 负责发送和处理消息
*/
public class Handler {
// 消息队列
private MessageQueue messageQueue;
// 消息泵
Looper looper;
public Handler() {
looper = Looper.getLocalLooper();
if (looper == null) {
throw new RuntimeException("Can't create handler inside thread that has not called Looper.prepare()");
}
messageQueue = looper.messageQueue;
}
public final void sendMessage(Message msg) {
MessageQueue queue = messageQueue;
if (queue != null) {
msg.handler = this;
queue.enqueueMessage(msg);
} else {
throw new RuntimeException(this + " sendMessage() called with no mQueue");
}
}
/**
* 子类必须实现此方法接收处理消息
* Subclasses must implement this to receive messages.
*/
public void handleMessage(Message msg) {
}
/**
* 在此处理系统消息
* Handle system messages here.
*/
public void dispatchMessage(Message msg) {
handleMessage(msg);
}
}