我想使用 IntentService 从Internet下载.我通过调用 startService(intentserive); .通过 Intent 将URL传递给 IntentService .
如果我为各种意图调用 startService ,那么意图会进入下载队列吗?
解决方案您的问题的简短答案是是".从文档中:
IntentService是处理异步的Services的基类请求(表示为Intent).客户发送请求通过startService(Intent)调用;该服务将根据需要启动,依次使用辅助线程处理每个Intent,并自行停止当它用完了.
此工作队列处理器"模式通常用于卸载任务从应用程序的主线程.IntentService类存在于简化此模式并注意机制.要使用它,扩展IntentService并实现onHandleIntent(Intent).IntentService将接收Intent,启动工作线程,并适当停止服务.
所有请求都在单个工作线程上处理-它们可能会被视为只要有必要(并且不会阻塞应用程序的主循环),但一次只能处理一个请求.
官方文档链接
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?
解决方案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
更多推荐
多次调用IntentService的startService时,intent会进入队列吗?
发布评论