- // Step 1: 创建并启动 HandlerThread 线程, 内部包含 Looper
- HandlerThread handlerThread = new HandlerThread("gityuan.com");
- handlerThread.start(http://www.amjmh.com/v/);
- // Step 2: 创建 Handler
- Handler handler = new Handler(handlerThread.getLooper()) {
- public void handleMessage(Message msg) {
- // process incoming messages here
- }
- };
- // Step 3: 发送消息
- handler.post(new Runnable() {
- @Override
- public void run() {
- System.out.println("thread id="+Thread.currentThread().getId());
- }
- });
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
上面就是 Android 系统中异步消息处理线程的通用写法
来源: http://www.bubuko.com/infodetail-3159674.html