有没有办法告诉如果收到LocalBroadcastManager广播? [英] Is there a way to tell if LocalBroadcastManager broadcasts were received?

查看:384
本文介绍了有没有办法告诉如果收到LocalBroadcastManager广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉如果收到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() returns true 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 use sendBroadcast() to try to send a message to your running Service, if it exists. If it does, sendBroadcast() should return true, and the IntentService knows that the message should be handled there. If sendBroadcast() returns false, you can raise the Notification.

这篇关于有没有办法告诉如果收到LocalBroadcastManager广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆