문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top