Interprocess communication (IPC) mode

  • The Bundle implements the Parcelable interface

    • Pros: Easy to use
    • Disadvantages: Can only pass data types supported by the Bundle
    • Usage scenario: Process communication between four components
  • File sharing

    • Pros: Easy to use
    • Disadvantages: Not suitable for high concurrency scenarios, cannot do even communication
    • Usage scenario: No concurrent access scenario, simple data exchange, low real-time requirements
  • AIDL

    • Advantages: powerful, support one-to-many concurrent communication, support real-time communication
    • Cons: Must deal with thread synchronization
    • Usage scenario: One-to-many communication requires remote Procedure Call Protocol (RPC)
  • Message

    • Advantages: general function, support one to many serial communication, support real-time communication
    • Disadvantages: Does not handle high concurrency scenarios, does not support RPC, and data is transmitted via Message, so supports only the data types supported by bundles
    • Usage scenario: low concurrency one-to-many real-time communication, no RPC requirement or RPC with no results returned
  • ContentProvider

    • Advantages: Mainly used for data access and supports one-to-many concurrent data sharing
    • Disadvantages: restricted, the main branch of the data source has been deleted
    • Usage scenario: One-to-many data sharing
  • Socket (Socket)

    • Advantages: powerful function, through the read and write network transmission byte stream, support one-to-many and call real-time communication
    • Disadvantages: Does not support direct RPC
    • Usage scenario: Exchange vioxx data
  • BroadcastReceiver

    • Advantages: Simple operation and support one-to-many real-time communication
    • Disadvantages: Only supports one-way data transmission, low efficiency and low security
    • Usage scenario: One-to-many low-frequency unidirectional communication

Binder mechanism

  • Introduction to the

    • AIDL, Messenger, Socket, And ContentProvider all use Binder mechanisms to implement interprocess communication
  • Why Binder as the main IPC method

    • Binder is an Android IPC interprocess communication structure that uses MMAP, a memory mapping mechanism
    • Binder’s entire design is C/S structure. A client process communicates with a server process by acquiring its proxy and reading and writing data to this proxy interface method
  • Binder is Android’s choice for two reasons

    • Security, each process will be assigned by the Android system UID and PID, do not want to add the traditional UID in the data, so that those malicious processes can not directly communicate with other processes, inter-process communication security is improved
    • Efficient, with IPC’s like sockets requiring two copies per copy, binders require only one, which is important in resource-constrained situations like phones