I have an IntentService
that starts an asynchronous task in another class and should then be waiting for the result.
The problem is that the IntentSer
Use the standard Service
class instead of IntentService
, start your asynchronous task from the onStartCommand()
callback, and destroy the Service
when you receive the completion callback.
The issue with that would be to correctly handle the destruction of the Service
in the case of concurrently running tasks as a result of the Service
being started again while it was already running. If you need to handle this case, then you might need to set up a running counter or a set of callbacks, and destroy the Service
only when they are all completed.