gpt4 book ai didi

android - Android 中具有多个 AIDL 接口(interface)的单一服务

转载 作者:行者123 更新时间:2023-12-02 15:51:51 24 4
gpt4 key购买 nike

如何从单个服务提供多个 AIDL 接口(interface)?场景如下:

                    |---Client_1
|--AIDL1--| ...
| |---Client_6
MyService |
| |---Client_4
|--AIDL2--| ...
|---Client_9
  • 具有多个 AIDL 的单一服务;
  • 每个客户端都可以访问任意数量的 AIDL 接口(interface);
  • 为了更好地理解,请考虑上图,其中一些客户端(例如 Client_1、Client_8)仅使用一个接口(interface),而其他客户端(例如 Client_4、Client_5、Client_6)同时访问 AIDL1 和 AIDL2。

我的想法是使用方法public IBinder onBind(Intent Intent)中的 Intent 以某种方式找出调用的客户端应用程序的类型AIDL 该客户对此感兴趣。这可能吗?

最佳答案

我也有同样的问题,写了原型(prototype)进行测试。实际上它应该通过检查 Intent 并根据 Intent 额外返回不同的绑定(bind)器来工作。

但是经过测试,我发现 onBind 只对第一个客户端调用一次。之后,系统会将缓存的binder返回给后续想要绑定(bind)该服务的客户端。

安卓 official document描述

Multiple clients can connect to the service at once. However, the system calls your service's onBind() method to retrieve the IBinder only when the first client binds. The system then delivers the same IBinder to any additional clients that bind, without calling onBind() again.

我仍在尝试寻找方法,但似乎不可能做到这一点。

关于android - Android 中具有多个 AIDL 接口(interface)的单一服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com