Thank you. 

I created a global variable int N and a boolean FLAG 

and use a method to initiate

void function() {
    N = 0;
    FLAG_COMMAND = true;
    mService.write(command((byte) N));
}



private final Handler mHandler = new Handler()
 {
     @Override
     public void handleMessage(Message msg) { 
             switch (msg.what) { 
case MESSAGE_READ:
byte[]readBuf = (byte[]) msg.obj;

Packet rPacket = new Packet(readBuf);

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


Now it works, but the code is dirty and inefficient, I want to know how to 
do it in a *normal* way, but not "Trying to shoehorn the synchronous model 
into the asynchronous model".

-- 
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