Question

I have a IntentService that connects to bluetooth (blocking part), sends data, and disconnects. I have modified IntentService to handle a special intent that will stop the service. However, it seems that because of blocking code, which connects to a bluetooth device (indefinitely or until canceled by user, as intended), the overriden onStart or onStartCommand is not called untilthe blocking part of code is no longer blocking.

Could the code inside onHandleIntent be blocking other intents reaching the service?

Was it helpful?

Solution

Yes. IntentService uses a single worker thread.

Or to quote the docs exactly:

All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but only one request will be processed at a time.

From https://developer.android.com/reference/android/app/IntentService.html

This means that only one call to onStartCommand can be happening on the IntentService at a time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top