Comparison and summary of several process communication methods in Android

What is IPC

IPC stands for Inter-Process Communication.

Android is based on Linux, and Linux, for security reasons, cannot operate each other's data between different processes, which is called "process isolation".

In the Linux system, the virtual memory mechanism allocates a linearly continuous memory space for each process. The operating system maps this virtual memory space to the physical memory space. Each process has its own virtual memory space and cannot operate other processes. Memory space, only the operating system has permission to operate the physical memory space. 

Process isolation guarantees the memory safety of each process.

But in most cases, data communication between different processes is unavoidable, so the operating system must provide a mechanism for cross-process communication.

Android several process communication methods

Cross-process communication requires that a method call and its data be decomposed to a degree that the operating system can recognize, transferred from the local process and address space to a remote process and address space, and then reassembled and executed in the remote process.

The return value will then be transferred back in the opposite direction.

Android provides us with the following process communication mechanisms (process communication APIs for developers)

Here is a summary of the comparison:

  • It is only necessary  to use IPC to allow clients of different applications to call remote methods and want to handle multithreading in the serviceAIDL
  • If you need to call remote methods, but do not need to handle concurrent IPC, you should  Binder create an interface by implementing a
  • If you want to perform IPC, but just pass data, no method calls are involved, and high concurrency is not required,  Messenger implement the interface using
  • If you need to handle one-to-many inter-process data sharing (mainly CRUD of data), use ContentProvider
  • If you want to implement one-to-many concurrent real-time communication, use Socket



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324732618&siteId=291194637