Maintain bluetooth connection even after call to onStop

自作多情 提交于 2019-12-13 05:54:23

问题


Currently, I connect my tablet to other devices (through Bluetooth). The connection is successful, but if the activity is paused and stopped, say when the home screen is pressed, it will disconnect for sure. I can always reconnect in OnStop() or something, but I want to maintain the connection throughout, unless the app process is destroyed altogether. How should I go about this?


回答1:


Handling that in your Activity is not a way to go - as you noticed, Activities stop executing and drop your Bluetooth connections.

You should create a Service which will handle your Bluetooth connectivity and keep running after your main Activity stops. Be sure to add an icon to notification bar to keep users notified that your application is still running in the background and burning battery.



来源:https://stackoverflow.com/questions/11938871/maintain-bluetooth-connection-even-after-call-to-onstop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!