We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
各种 IPC 方式的优缺点和适用场景(参考《Andoid开发艺术探索》,并按自己的理解做了改动)
其中 AIDL、Messenger、ContentProvider 都是基于 Binder
(1)Client 调用 Stub 接口的方法 A (2)直接由 (3)Service 中该接口的实现响应。 (4)直接由 (5)Client 方法 A 返回
(1)Client 调用 Stub 接口的方法 A (2)在 Client 端,由 Stub 的内部类 Proxy 响应,并将方法id 和参数序列化,通过 transact 方法传到底层,Client 端线程阻塞。在 Service 端,系统(线程池)回调onTransact 方法,反序列化,并调用不同的 Stub 接口方法。 (3)Service 中该接口的实现响应。 (4)onTransact 方法得到结果并序列化,返回 true 标记成功,transact 方法线程阻塞解除,得到结果并反序列化,返回结果。 (5)Client 方法 A 返回
可以看出来非IPC 与 IPC 的区别只有第(2)(4)步,而这一步的代码是通过 .aidl 文件生成的,也就是系统屏蔽了进程间通信的具体实现,只暴露给开发者(1)(3)(5)三步,使得在开发者的眼里,IPC 就好像在同一个进程中一样,实现起来非常简单。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
各种 IPC 方式的优缺点和适用场景(参考《Andoid开发艺术探索》,并按自己的理解做了改动)
其中 AIDL、Messenger、ContentProvider 都是基于 Binder
简化的 Binder 应用层原理图:
调用过程解析
非 IPC:
(1)Client 调用 Stub 接口的方法 A
(2)直接由
(3)Service 中该接口的实现响应。
(4)直接由
(5)Client 方法 A 返回
IPC:
(1)Client 调用 Stub 接口的方法 A
(2)在 Client 端,由 Stub 的内部类 Proxy 响应,并将方法id 和参数序列化,通过 transact 方法传到底层,Client 端线程阻塞。在 Service 端,系统(线程池)回调onTransact 方法,反序列化,并调用不同的 Stub 接口方法。
(3)Service 中该接口的实现响应。
(4)onTransact 方法得到结果并序列化,返回 true 标记成功,transact 方法线程阻塞解除,得到结果并反序列化,返回结果。
(5)Client 方法 A 返回
可以看出来非IPC 与 IPC 的区别只有第(2)(4)步,而这一步的代码是通过 .aidl 文件生成的,也就是系统屏蔽了进程间通信的具体实现,只暴露给开发者(1)(3)(5)三步,使得在开发者的眼里,IPC 就好像在同一个进程中一样,实现起来非常简单。
The text was updated successfully, but these errors were encountered: