Bluetooth streaming or Android service?

I am developing an application that uses bluetooth connectivity. The Bluetooth connection must continue even if the activity that establishes the connection is closed. Firstly, I thought about using the Service for this, and it seemed right. But in the example of the Bluetooth chat, the connection occurs in a different thread, and not in the Service. I used this code in my application and it works correctly. Does Thread use bluetooth properly, or do I only need to use the service? The Bluetooth connection should be active until my application is in RAM, and it does not matter if I switch between actions.

+4
source share
2 answers

Well, a separate section is not different from you in your case, except that it follows the Android activity life cycle, but the thread can be killed and the state can not be restored. Android will try to restart the service after it is killed.

0
source

It's too late to answer your request, but better late than never. I was working on an application that has Bluetooth connectivity between two devices, and I would like to summarize my experience. The service that we usually use when we want does some kind of background process that is not very heavy, in a sense, I mean that the service (if it is huge) blocks my main UI thread, so slowing down your OS or ANR may be what we don’t want.

Bluetooth communication is an ongoing process that must be performed using Thread only when it works as a separate thread and does not affect the main thread of the user interface. Please correct me if I am wrong.

0
source

All Articles