问一个IntentService有关其队列信息队列、信息、IntentService

2023-09-05 00:03:12 作者:面具

我有排队需要作出我的Web服务器的Web服务调用的IntentService。所以,每一个意图是一个Web服务调用进行。

我想设置了东西在我的应用程序可以问这个IntentService如果有包含特定一块数据(即任何意图:你已经轮候提出云计算的X数据或者我需要什么?告诉你这样做吗?)。

有没有,我怎么可能会延长IntentService做到这一点有什么建议?一个IntentService的意图队列可以遍历?我会不会需要采取IntentService code和改变它?

唯一的其他想法我已经是一个表添加到数据库和日志这就要求在排队,从表中删除每个日志完成时。

解决方案   

有没有,我怎么可能会延长IntentService做到这一点有什么建议?一个IntentService的意图队列可以遍历?我会不会需要采取IntentService code和改变它?

大概是后者,如果你真的要检查实际的队列。 IntentService 变成了意图插入邮件弹出一个尺蠖的消息队列通过 HandlerThread 。这些都不是通过SDK露出,虽然。幸运的是, IntentService 是相当短的 - 甚至不是150行。你可以克隆它变成你自己的包,并根据需要进行修改。只要运行在新的源更新发布在AOSP库源上的差异,所以你知道,如果谷歌进行任何重大手术 IntentService 本身,你可能想利用的。

  

唯一的其他想法我已经是一个表添加到数据库和日志这就要求在排队,从表中删除每个日志完成时。

这甚至不需要是持久的那样,因为 IntentService 的自己的队列是不持久的。只要保持在 onStartCommand自己的FIFO队列(),链接到父,并弹出你的意图关闭队列 onHandleIntent结束时()。这有失控与主队列同步的机会(比如,你需要使用最后,以确保你弹出的工作把你自己的队列),但你不会有克隆类

I have an IntentService that queues up web service calls that need to be made to my web server. So each Intent is a web service call to be made.

I'd like to set something up where my application can ask this IntentService if it has any Intents containing a particular piece of data (IE: "Are you already waiting to ask the cloud for x data? Or do I need to tell you to do it?").

互联网业务场景下消息队列架构

Are there any suggestions on how I might extend IntentService to do this? Can the Intent queue of an IntentService be traversed? Or would I need to take the IntentService code and alter it?

The only other idea I have is to add a table to the database and log which calls are in the queue, with each log being removed from the table when completed.

解决方案

Are there any suggestions on how I might extend IntentService to do this? Can the Intent queue of an IntentService be traversed? Or would I need to take the IntentService code and alter it?

Probably the latter, if you really want to examine the actual queue. IntentService turns the Intents into messages popped on the message queue of a Looper via a HandlerThread. None of that is exposed through the SDK, though. Fortunately, IntentService is fairly short -- not even 150 lines. You could clone it into your own package and make modifications as needed. Just run a diff on the source when new source updates are released in the AOSP repository, so you know if Google performed any major surgery on IntentService itself that you might want to take advantage of.

The only other idea I have is to add a table to the database and log which calls are in the queue, with each log being removed from the table when completed.

It wouldn't even need to be persistent like that, since the IntentService's own queue is not persistent. Just maintain your own FIFO queue in onStartCommand(), chaining to the superclass, and popping your Intent off the queue at the end of onHandleIntent(). This has a chance of getting out of sync with the master queue (e.g., you'll want to use finally to ensure you pop the work off your own queue), but you wouldn't have to clone the class.