在 Looper.getMainLooper())之外接收适当的数据 我不明白为什么在Looper.getMainLooper()中接收垃圾数据。
public class A1Service extends PresentationService implements
Runnable {
switch(dataId) {
case 0x2b:
Log.d("AAA", "speed_data==>" + speed +"speed_id:--------"+ Data[0]);//here receiving properdata
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.d("AAA", "speed_data==>" + speed +"speed_id:"+ Data[0]);//here receiving junk data
}
});
break;
case 0x40:
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.d("AAA", "rpm_data==>" + rpm +"id:--------"+ Data[0]);//here receiving junk data
}
});
break;
Logcat:
speed_data==>537 speed_id:64
speed_data==>17 speed_id:--------43
speed_data==>538 speed_id:64
speed_data==>18 speed_id:--------43
speed_data==>1 speed_id:88
speed_data==>19 speed_id:--------43
speed_data==>1 speed_id:90
speed_data==>20 speed_id:--------43
speed_data==>1 speed_id:92
speed_data==>21 speed_id:--------43
speed_data==>25 speed_id:94
speed_data==>22 speed_id:--------43
答案 0 :(得分:0)
我的问题已使用AsyncTask解决。
喜欢
private class CustomTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... param) {
return null;
}
protected void onPostExecute(Void param) {
case 0x2b:
Log.d("AAA", "speed_data==>" + speed +"speed_id:--------"+ Data[0]);//here receiving properdata
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.d("AAA", "speed_data==>" + speed +"speed_id:"+ Data[0]);//here receiving junk data
}
});
break;
case 0x40:
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Log.d("AAA", "rpm_data==>" + rpm +"id:--------"+ Data[0]);//here receiving junk data
}
});
break;