Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does intent go queue when calling startService for IntentService multiple times?

I want to download from internet with a IntentService. I pass a url through Intent to IntentService by calling startService(intentserive);.

If I call startService for a various intents, do the intents go queue for download?

like image 532
user3900720 Avatar asked Feb 08 '15 11:02

user3900720


People also ask

Can an intent Service execute multiple tasks sequentially?

No, each IntentService only has one HandlerThread that it uses to execute requests in the order that "startService" is called.

What happens if multiple intents are passed to a started service?

The Service will only run in one instance.

Does intent Service run on main thread?

If the Background task is to be performed for a long time we can use the intent service. Service will always run on the main thread. intent service always runs on the worker thread triggered from the main thread.

How does intent service work in Android?

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent, in turn, using a worker thread, and stops itself when it runs out of work.


1 Answers

The short answer to your question is YES. From the docs:

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

This "work queue processor" pattern is commonly used to offload tasks from an application's main thread. The IntentService class exists to simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate.

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.

Official docs link

like image 153
Manish Kumar Avatar answered Oct 18 '22 22:10

Manish Kumar