在我的代码中,我使用Android Smooth Bluetooth库与微控制器进行通信。 响应字节将自动读入侦听器
@Override
public void onDataReceived(int data) {
//receives all bytes
mBuffer.add(data); // mBuffer = new ArrayList<>();
if(mBuffer.size() == bytesExpected){
//-->>
}
}
如何在按下按钮后继续进行其他操作之前,如何等待ArrayList(mBuffer)完成?
display_status.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBuffer.clear();
bytesExpected = 1088;
byte[] display_status = {13,10,0,86,1,0,0,0,0,13,10};
mSmoothBluetooth.send(display_status);
//-- Here I want to wait that all bytes are arrived before proceed --//
//--- Read mBuffer and use the bytes ---//
}
});