其他分享
首页 > 其他分享> > android – 询问IntentService以获取有关其队列的信息

android – 询问IntentService以获取有关其队列的信息

作者:互联网

我有一个IntentService,它将需要对我的Web服务器进行的Web服务调用进行排队.因此,每个Intent都是要进行的Web服务调用.

我想设置一些东西,我的应用程序可以询问这个IntentService,如果它有任何包含特定数据的Intent(IE:“你是否已经在等待向云询问x数据?或者我是否需要告诉你做到了吗?“).

关于如何扩展IntentService来做这个有什么建议吗?是否可以遍历IntentService的Intent队列?或者我需要获取IntentService代码并进行更改吗?

我唯一的另一个想法是向数据库添加一个表并记录哪些调用在队列中,每个日志在完成后从表中删除.

解决方法:

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?

可能是后者,如果你真的想检查实际的队列. IntentService通过HandlerThread将Intent转换为Looper的消息队列中弹出的消息.但是,这些都不是通过SDK公开的.幸运的是,IntentService相当短 – 甚至不到150行.您可以将其克隆到您自己的包中,并根据需要进行修改.在AOSP存储库中发布新的源更新时,只需在源上运行差异,这样您就可以知道Google是否对您可能想要利用的IntentService本身进行了任何重大手术.

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.

它甚至不需要像那样持久化,因为IntentService自己的队列不是持久的.只需在onStartCommand()中维护自己的FIFO队列,链接到超类,然后在onHandleIntent()的末尾从队列中弹出Intent.这有可能与主队列不同步(例如,您最终要使用以确保从自己的队列中弹出工作),但您不必克隆该类.

标签:intentservice,android,android-intentservice
来源: https://codeday.me/bug/20190928/1828083.html