Search code examples
androidandroid-intentservice

If an IntentService object is processed completely and takes indefinite time, how will other queued up intents be processed?


I have a Class ABC which extends IntentService. This class is called by a receiver class named DEF which extends WakefulBroadcastReceiver.

Whenever DEF class receives an intent, it calls startWakefuleService and passes the intent to the ABC class.

In the onHandle() of ABC class, the intent is processed and relevant information is sent to the server using callback.

At the end of the onHandle(), DEF.completeWakefulIntent(intent) is called to return the Wake Lock.

My question is about the following scenario:

  1. My BroadcastReceiver class DEF, received multiple intents

  2. It started multiple IntentServices through class ABC.

  3. The first Intent Service makes the http request to the server, which takes lot of time to come back or does not come back at all.

Will the other Intent Service that are started be process or will they get stuck in the queue waiting to be processed?

The [documentation] (https://developer.android.com/reference/android/app/IntentService.html) says that the IntentService objects are processed sequentially.

Any help would be appreciated.


Solution

  • All requests to IntentService are handled on a single thread and complete sequentially. If a request blocks onHandleIntent() and prevents it from completing, further requests will never be processed.

    There is only one instance of a Service. There is no such thing as "the other IntentService".

    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.