没有处理程序的广播接收器(最佳实践)
我有 2 个独立的应用程序 appA 和 appB。
如果手机上不存在这两个应用程序,则没有问题:)。
如果两者都再次出现,则没有问题,因为 appA 发送广播,而 appB 处理该广播。
有趣的场景是当 appA 存在但 appB 不存在时。
-appA 是否应该发送广播
,或者
-appA 应检查 appB 是否存在并仅在 appB 存在时才发送广播。
注意:无论是否有人处理广播,appA 都不需要任何反馈...
但是正确的方法是什么?
当发送广播并且没有人处理该广播时,通常会发生什么?
I have 2 separate applications appA and appB.
if both app are not present on phone no problems here :).
if both present again no problems here, because appA sends a broadcast and appB it handles that broadcast.
The interesting scenario is when appA is present but appB is not present.
-Should appA send a broadcast anyway
or
-appA should check if appB is present and send the broadcast only if appB is present.
Note:appA doesn't need any feedback if someone handles the broadcast or not...
But what is the right way to do this?
What happens in general when broadcast is send and no one handles that broadcast ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有任何东西可以处理广播,则什么也不会发生。由于您不关心它是否已被处理,因此只需广播它而不进行检查就足够了。
If there's nothing to handle the broadcast, nothing happens. Since you don't care about whether it was handled, it should be sufficient just to broadcast it without checking.