在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
我的问题是使用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;