有没有办法告诉如果收到LocalBroadcastManager广播? [英] Is there a way to tell if LocalBroadcastManager broadcasts were received?
问题描述
有没有办法告诉如果收到LocalBroadcastManager广播?或正在聆听?
基本上我有一个IntentService收听谷歌云的消息。当它得到一个我需要或者显示通知或报警我的主要服务有已经有新的消息 - 关键的是,我不希望两个!所以,我需要知道消息是否是由我的主要业务处理...
显然,它可以与sendOrderedBroadcast和广播接收器来完成,但似乎矫枉过正我简单的私有进程内的需求。
有没有办法告诉如果收到LocalBroadcastManager广播?或正在聆听?
块引用>
sendBroadcast()
收益真正
如果有1 +接收器,假
其它。这是没有记录,但是这是基于当前的实现。我申请一个问题得到记录。因此,你的
IntentService
可以使用sendBroadcast()
来尝试发送邮件到您运行服务
,如果它存在。如果是这样,sendBroadcast()
应该返回真正
和IntentService
知道该消息应该在那里处理。如果sendBroadcast()
收益假
,可以提高通知
。Is there a way to tell if LocalBroadcastManager broadcasts were received? Or are being listened to?
Basically I have an IntentService listening for Google Cloud Messages. When it gets one I need to either show a notification OR alert my main Service that there's been a new message - crucially I don't want both! So I need to know whether the message was dealt with by my main Service ...
Clearly it can be done with sendOrderedBroadcast and a BroadcastReceiver but that seems overkill for my simple private intra-process needs.
解决方案Is there a way to tell if LocalBroadcastManager broadcasts were received? Or are being listened to?
sendBroadcast()
returnstrue
if there was 1+ receivers,false
otherwise. That's not documented, but that is based on the current implementation. I filed an issue to get that documented.Hence, your
IntentService
could usesendBroadcast()
to try to send a message to your runningService
, if it exists. If it does,sendBroadcast()
should returntrue
, and theIntentService
knows that the message should be handled there. IfsendBroadcast()
returnsfalse
, you can raise theNotification
.这篇关于有没有办法告诉如果收到LocalBroadcastManager广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!