close()和disconnect()之间的区别? [英] Difference between close() and disconnect()?
问题描述
Android蓝牙低功耗API实现了一种方法来连接到设备connectGatt()
,但是实现了两种方法来关闭连接disconnect()
和close()
.
Android Bluetooth Low Energy API implements 1 method to connect to the device connectGatt()
but 2 methods to close the connection disconnect()
and close()
.
文档说:
-
disconnect()
:断开建立的连接,或取消连接尝试 目前正在进行中.
disconnect()
: Disconnects an established connection, or cancels a connection attempt currently in progress.
close()
:完成后,应用程序应尽早调用此方法
这个GATT客户.
close()
: Application should call this method as early as possible after it is done with
this GATT client.
的源代码BluetoothGatt.java 显示close()取消注册应用程序,disconnect()断开客户端连接.但是,它没有说出实际含义.我的意思是,如果只有一种方法可以连接到客户端,为什么有两种方法可以关闭/断开连接?
The source code of BluetoothGatt.java shows that close() unregisters the application and disconnect() disconnect the client. However it does not say what that actually means. I mean, if there is only 1 way to connect to the client, why there are 2 ways to close/disconnect the connection?
推荐答案
使用disconnect()
,您以后可以调用connect()
并继续该循环.
With disconnect()
you can later call connect()
and continue with that cycle.
一旦您致电close()
,您就完成了.如果要再次连接,则必须再次调用BluetoothDevice
上的connectGatt()
;否则,将重新调用. close()
将释放BluetoothGatt
拥有的所有资源.
Once you call close()
you are done. If you want to connect again you will have to call connectGatt()
on the BluetoothDevice
again; close()
will release any resources held by BluetoothGatt
.
这篇关于close()和disconnect()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!