I have an issue with disconnection and connection process. Assume that I have a button which allow to disconnect the previous Bluetooth Low Energy device and connect with a new BLE device. Normally, the disconnection process take about 500ms->1second, thus, I have to make a delay process which aim to wait until disconnection process finishing. Then I will call the new connection process. This is my code
public void onClickButton( View v){
//Disconnect previous
mBluetoothLeService.disconnect();
//Need to wait here...
//Connect with new BLE
mBluetoothLeService.connect(mDeviceAddress);
}
Do you think Timer, Handler, or Thread is best choice in my case? Thank all
This is my solution using timer
final ProgressDialog waitProgressDialog = ProgressDialog.show(this, "Please wait ...", "Disconnecting ...", true);
waitProgressDialog.setCancelable(true);
new CountDownTimer(500,100) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
waitProgressDialog.dismiss();
}
}.start();
Seems like the wrong solution to try to estimate time since it depends on the connection parameters how long time it will take to disconnect since the device will wait for an acknowledgment that the peripheral has received the command.
Instead just wait for the onConnectionStateChange callback.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.