ericn
ericn

Reputation: 13103

Use a bound service vs create a new thread in Android

I suppose the main selling point of started service is that it can outlive an application itself to do something like downloading a lot of data.

What about a bound service compared to a new thread? A bound service lives until it's completely unbind which is as long as the application runs in my understanding. Why not just start a new thread instead e.g. to handle Bluetooth connection and data transfer?

The motivation behind my question is that I'm reading the code of the BluetoothHDP sample and the use of a bound service there confuses me.

Upvotes: 2

Views: 420

Answers (1)

Pulkit Sethi
Pulkit Sethi

Reputation: 1325

Service you want to use when you want to do something non UI specific and not UI dependent. Starting a thread in UI is still UI dependent since your main thread becomes it parent. If you rotate device all threads get destroyed, however servie can continue to run. thats y for Bluetooth you would have service. similar case for lets say voice recording.

Upvotes: 1

Related Questions