I am working on Android Application which have service class. I service class, I have to start a thread. It is working fine. But I need to stop the thread. I have used with
mThread.destroy();
mThread.stop();
but both are deprecated and i have used
mThread.interrupt();
but it still does not work.
code
public void Receivepatientattributes(byte[] readBuf, int len) {
if (readBuf[8] == 6){
pktcount++;
byte pkmsb = readBuf[11];
byte pklsb = readBuf[10];
int pkresult = (pkmsb << 8) | ((int)pklsb & (0x00FF));
System.out.println("Packet : "+pktcount+" : "+pkresult);
if(pkresult == pktcount){
for(int i = 0, j = 14; i < len ; i++, j++) {
queue.add(readBuf[j]);
}
if(mThread.getState() == Thread.State.NEW) {
mThread.start();
System.out.println("Start Thread ");
} else {
System.out.println("No Thread Found");
}
} else {
displayToast("Packet Count Error");
}
}
}
}
class CommunicationThread implements Runnable {
@Override
public void run() {
do{
if(queue.getFirst() == (byte)0x80) {
System.out.println("absolu1 " + queue.getFirst());
getabs_data();
}
} while (queue.size() > 132);
if(mThread.getState() == Thread.State.RUNNABLE) {
mThread.interrupt();
}
}
}