Can Messenger (lightweight alternative to AIDL) be used for cross-application communication?

假装没事ソ 提交于 2019-12-06 02:05:10

问题


A quick question: the Android docs say very clearly that Messenger is an alternative for AIDL for IPC (inter process communication). They never explicitly say though if this extends to processes running in different applications, or just within one app. I strongly suspect the former, but wanted to check.

Thanks! Jan


回答1:


AIDL is only really used for inter-app IPC. While it is possible to use AIDL for internal communication, it doesn't buy you anything and puts limitations on your Binder implementations.

Moreover, one application does not have more than one process, in the vast majority of cases. There is little reason for most apps to have multiple processes.

Messenger, createPendingResult(), ResultReceiver, private broadcast Intents -- all of these are ways for a service to communicate with a client across process boundaries.




回答2:


Messenger internally uses AIDL,it can be used in multiple applications.As per android documentation a Messenger service can be used for communication between two processes but it does not restrict it in same application.Processes can be in same application or different application.

Messenger should be used if we want the requests to be processed sequentially as it enters the messages in handler's queue and they are processed one by one whereas in AIDL all requests will be handled at once and it becomes developer's responsibility to maintain thread safety.



来源:https://stackoverflow.com/questions/5485285/can-messenger-lightweight-alternative-to-aidl-be-used-for-cross-application-co

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!