Yes, you are right, it is not inefficient, my fault. 

The activity has a button, after clicked, it will *call* function(). 

However, the code I posted last time is wrong (see the N-- part), I've 
changed the code a little bit:


case MESSAGE_READ:
byte[]readBuf = (byte[]) msg.obj;


Packet rPacket = new Packet(readBuf);

if (FLAG_COMMAND &&  N <= 10) {
if (rPacket.isValid()) {
dosomething(rPacket);
N++;
} 
mSerinusService.write(command((byte) N));
} else if (FLAG_COMMAND && N >= 10) {
FLAG_COMMAND = false;
N = 0;
}
                                break;

When the activity receives some data, it will check if FLAG_COMMAND is true 
and if N is less than 10 (which means the task hasn't been done).
  If yes, then check if the data received is valid
     if yes, do something with the data, and N++, then write a command(N) 
to the outputStream.

     if no, write command(N) (N hasn't been changed in this case) to the 
outputStream again.

And if N has reached 10, set FLAG_COMMAND to false and reset N.



But it doesn't work...I think there is some logic mistake in my code. 







-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to