保持蓝牙连接即使调用的onStop [英] Maintain bluetooth connection even after call to onStop

查看:159
本文介绍了保持蓝牙连接即使调用的onStop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,连接我的平板电脑与其他设备(通过蓝牙技术)。连接成功,但如果活动被暂停,停止,说当主屏幕是pssed,它将肯定断开$ P $。我总是可以重新连接调用OnStop()什么的,但我想在整个保持连接,除非该应用程序是完全破坏。我应该如何去吗?

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?

推荐答案

处理,在你的活动是不是很长的路要走 - 因为你注意到没有,活动停止执行拖放蓝牙连接

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.

这篇关于保持蓝牙连接即使调用的onStop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆