为什么android中需要使用线程来接收蓝牙远程设备的数据?
我最近一直在对我的工作项目进行一些研究,我正在尝试从我的应用程序中的蓝牙读卡器读取刷卡数据。
为了获取数据,我必须使用线程,我知道为什么需要使用线程,因为这个过程不会阻碍接口活动,但这里我关心的是不在获取数据时处理接口活动。但是当需要BluetoothServerSocket以获得全双工连接时,线程就有意义了。 所以我的问题基本上是,如果我只是从远程设备接收数据,我真的需要在线程下有一个BluetoothServerSocker吗?
I have been doing some research lately over my work project, i am trying to read card swipe data from Bluetooth card reader in my app.
So as to get that data i have to use thread, i know the reason why is there a need to use so as this process does not hinder interface activity, but here my concern is not to handle interface activity at the time of fetching data. But threading makes sense when there is a need of BluetoothServerSocket so as to have full duplex connection.
So my question basically is that if i am just receiving data from remote device do i really need to have a BluetoothServerSocker under Thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您正在执行某些需要花费一些时间的操作时,最好使用线程。当您从蓝牙读卡器读取数据时,在这种情况下,后台会发生许多活动。例如蓝牙连接、设备发现、配对、请求许可、检索数据。这可能是设备挂起的原因,或者用户可能不喜欢处于等待状态。因此,为了防止这种情况,最好使用线程。
When you are doing some action that is going to take some time in performance, then it is better to use Thread. When you are reading Data from Bluetooth Card Reader, then in this case, in background many activities take place. for e.g. Bluetooth Connection, Device Discovery, Pairing, Asking for permission , retrieving data. It may be possible cause of device hang or user may not like to be in wait state. so to prevent such cases it is better to use Thread.