码迷,mamicode.com
首页 > 其他好文 > 详细

实时轨迹数据排队问题

时间:2019-08-17 20:19:08      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:and   post   handle   proc   系统   ble   一个   int   ide   

一个标准的异步消息处理线程应该怎么写?
方法1:

class LooperThread extends Thread {
public Handler mHandler;

public void run() {
Looper.prepare();
mHandler = new Handler() {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
Looper.loop();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
方法2:

// 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系统中异步消息处理线程的通用写法

实时轨迹数据排队问题

标签:and   post   handle   proc   系统   ble   一个   int   ide   

原文地址:https://www.cnblogs.com/ly570/p/11369963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!