2 服务通信

发布于 2024-12-29 16:39:29 字数 204 浏览 4 评论 0原文

我有一个启动另一个远程服务的服务。当第二个服务启动时,它使用 IPC 绑定到第一个服务,一切都很好。

我的问题是,我希望第一个服务也能够与第二个服务通信(现在,只实现了相反的方式)。我可以用同一个 Binder 来做到这一点吗?或者我应该将第一个服务绑定到第二个服务? 也许有办法让两个服务在同一个连接上进行通信?

所有帮助将不胜感激。

弗拉德

I have a service that starts another remote service. when the second service have started, it binds to the first service using IPC, and all works great.

My question is, i would like the first service to be able to talk to the second service as well (right now, only the other way around is implemented). can i somehow do it with the same Binder? or should i bind the first service to the second one?
maybe there's a way to make two services talk on the same connection somehow?

All help would be appreciated.

Vlad

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雾里花 2025-01-05 16:39:30

如果您需要第一个 Service 来调用第二个 Service 上的方法,那么您需要从第二个 获取一个 Binder服务。如果您只想进行通信,可以使用Broadcasts并在第一个Service中设置一个Receiver

If you need the first Service to call methods on the second Service, then you'll need to get a Binder from the second Service. If you just want to communicate, you could use Broadcasts and set up a Receiver in the first Service.

白芷 2025-01-05 16:39:30

我认为使用同一个绑定器的双向通信对于服务来说是不可能的。我已经尝试了很多,并且我发现的问题,使用您自己的示例的说法是,从第二个服务检索的 IBinder 接口始终为空。
我的意思是,第一个服务必须绑定到第二个服务,以便获得有效的 IBinder 来与第二个服务通信。限制是,当第二个服务调用第一个服务时,它无法将接口传递给第一个服务,因此可以发生回调(从第一个服务到第二个服务)。
相反,需要建立与第二个服务的新的独立 IBinder 连接。希望有人能帮助我们解决这个问题。

阿尔贝托.

I think that two way communication using the same binder is impossible for services. I have tried a lot, and the problem I found, using the parlance of your own example is that IBinder interfaces retrieved from the second service are always null.
I mean, the first service would have bind to the second in order to obtain a valid IBinder to talk to the second service. The limitation is that when the second service calls the first, it cannot pass interfaces to the first service so callbacks(from first to second) can take place.
A new independent IBinder connection to the second service needs to be established, instead. Hope somebody can help us with this one.

Alberto.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文