jimmyC
jimmyC

Reputation: 563

Maintain bluetooth connection even after call to 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?

Upvotes: 0

Views: 755

Answers (1)

Mavrik
Mavrik

Reputation: 2630

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.

Upvotes: 2

Related Questions