android - 多次调用 IntentService 的 startService 时 Intent 是否进入队列?

标签 android android-intentservice

我想使用 IntentService 从 Internet 下载。我通过调用 startService(intentserive); 将 url 通过 Intent 传递给 IntentService

如果我为各种 Intent 调用 startService,这些 Intent 是否会排队等待下载?

最佳答案

您的问题的简短回答是肯定的。来自文档:

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

关于android - 多次调用 IntentService 的 startService 时 Intent 是否进入队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28393575/

相关文章:

java - 如何获得有关我的应用程序中发生的异常的更多详细信息?

java - 如何从与 Firebase 数据库同步的 ArrayList 中删除条目?

android - 无法在 okhttp3 Android 中访问 POST 参数

android - 由于设备内存不足,我的应用程序关闭

android - Android平台中的Service vs IntentService

android - 当 IntentService 启动时,Application 对象会启动吗?

android - cp : copyFileSync: could not write to dest file (code=ENOENT)

java - Android HttpUrlConnection 结果字符串被截断

android - 地理围栏有效,但一段时间后停止触发

java - 地理围栏 : HTTP request failed while sending through the background service. 给出 UnknownHostException