掉落的意图而IntentService是处理

掉落的意图而IntentService是处理

本文介绍了掉落的意图而IntentService是处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我理解正确的IntentService API文档,意图发送到IntentService排队,如果它是处理和顺序处理。

有没有一种简单的方法来告诉IntentService,它应该刚落发送给它,而它正在处理任何意图?

干杯,托

解决方案

没有,不是一个简单的方法,我知道的,但也许并不太难。

我想我已经看到了类似的问题,这和一个建议是简单地通过从Android源复制code定义自己的IntentService类(有少于150线code和一些这是注释)。

意图的队列'由嵌套类称为ServiceHandler延伸处理程序进行管理。如果从源头上定义自己的IntentService你可以添加的方法来清除消息队列,并终止该处理程序,如果它是在处理一个Intent的中间(如果这就是你所需要的)。

If I understand the API docs on IntentService correctly, intents sent to an IntentService queue up if it is processing and are processed sequentially.

Is there an easy way to tell IntentService that it should just drop any intents sent to it while it is processing?

Cheers,Torsten

解决方案

No, not an easy way that I know of but perhaps not too difficult.

I think I've seen a similar question to this and one suggestion was to simply define your own IntentService class by copying the code from the Android source (there's less than 150 lines of code and some of that is comments).

The 'queue' of Intents is managed by a nested class called ServiceHandler which extends Handler. If you define your own 'IntentService' from the source you could add methods to clear the message queue and even terminate the Handler if it is in the middle of processing an Intent (if that's what you need).

这篇关于掉落的意图而IntentService是处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:17