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

半世苍凉 提交于 2020-01-12 07:12:10

问题


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?


回答1:


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




回答2:


Yes. Intent service queues all the work intents and process them one by one in single worker thread.



来源:https://stackoverflow.com/questions/28393575/does-intent-go-queue-when-calling-startservice-for-intentservice-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!