多次调用IntentService的startService时,intent会进入队列吗?

编程入门 行业动态 更新时间:2024-10-28 18:34:49
本文介绍了多次调用IntentService的startService时,intent会进入队列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用 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会进入队列吗?

本文发布于:2023-11-26 23:57:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   IntentService   startService   intent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!