While I am not certain that this is the primary problem, I do find quite a bit of inefficiency in your code:
you are creating a lot of transient objects with this
for (byte i = 0; i < demoRxMsg.dataLength; i++) { data = data + Integer.toHexString(demoRxMsg.data[i]) + " "; }
For each byte you are creating at least two objects: one StringBuilder and one String object (ref here). If you want to get a String, at least make it like below:
StringBuilder sb=new StringBuilder(); for (byte i = 0; i < demoRxMsg.dataLength; i++) { sb.append(demoRxMsg.data[i]); } data=sb.toString();
Instead of comparing strings, it'll be much faster to compare raw bytes, this way you can skip any object creation altogether.
I assuming between the first and last few blocks of data, there are quite a bit of data in between, but in your current implementation those data that do not affect UI will still be checked on the UI thread, instead only run
mProgressBar.setProgress(progress);
when you have determined that UI needs to be updated. Untested code:class RxThread extends Thread { private static final String TEST = "0 0 0 0 0 40 0 0 "; private static final String TEST2 = "0 1 0 0 0 41 0 0 "; private static final String TEST3 = "2 bb 0 0 2 fb 0 0 "; private static final String TEST4 = "2 bd 0 0 2 fd 0 0 "; private static final String TEST5 = "2 be 0 0 2 fe 0 0 "; Handler myHandler = new Handler(); public void run() { while (true) { try { Thread.sleep(60); demoRxMsg = new MessageStructure(); int progress = -1; while (rxChannel.receiveMessage(demoRxMsg) == ReturnCode.SUCCESS) { String data = ""; String format = ""; rxChannel.receiveMessage(demoRxMsg); if (demoRxMsg.frameFormat == API_ADK.STANDARD_FRAME) { format = "SFF"; } else { format = "EFF"; } for (byte i = 0; i < demoRxMsg.dataLength; i++) { data = data + Integer.toHexString(demoRxMsg.data[i]) + " "; } if (data.equalsIgnoreCase(TEST)) { progress = 0; } else if (data.equalsIgnoreCase(TEST2)) { progress = 1; } else if (data.equalsIgnoreCase(TEST3)) { progress = 94; } else if (data.equalsIgnoreCase(TEST4)) { progress = 95; } else if (data.equalsIgnoreCase(TEST5)) { progress = 96; } } if (progress != -1) { final int newProgress = progress; myHandler.post(new Runnable() { public void run() { mProgressBar.setProgress(newProgress); } }); } } catch (InterruptedException e) { break; } }
} }