Android architect path-process and IPC architecture (1), androidipc

Source: Internet
Author: User

Android architect path-process and IPC architecture (1), androidipc

1. IPC Communication

2. android process concept

3. Set IPC Communication

4. IPC interface-definition and implementation

5. Use of the IBinder Interface

6. Step 3 of IPC Communication

7. Short-range communication and remote communication


1. First, let's look at the first big question: What is ipc communication?

IPC (Inter-Process Communication) Communication spans two different processes.

Generally, all components (activities and services) in an android application are executed in a process. Short-range communication is called short-range communication, this means that two activities are executed in the same process.

Remote Communication: two components (activity and service) are executed in different processes respectively. to communicate, the two components must communicate through IPC. This is called remote communication.

IPC communication efficiency:

Start the app. The Zygote service in the android system incubated a new process for the app, and then loaded the app into the new process.

Based on Linux security restrictions and basic features of processes, the address space of different processes is independent. If two classes are executed in the same process, the communication between the two is convenient and fast.

Cross-process communication is required for different processes.

2. android process concept

A process is an independent execution space and will not be infringed by programs in other processes. This protection method is an important security mechanism for Android. Therefore, we must first understand the meaning of processes to further understand the cross-process IPC Mechanism.
• In the Android process, there is a Virtual Machine (VM) object that can execute Java code and guide JNI local program execution, implement communication between Java and C/C ++


At the birth of each process, a Main Thread will be created, and a logoff class object and a Message Queue data structure will be created. Every time the main thread finishes the task, it will execute the logoff class.

The main task of the main thread is to process the Event of the UI screen. When a UI Event occurs, the Android framework will lose the Message to MQ. When the main thread sees that MQ has new information, it retrieves the information and then executes the specific function based on the information content. After the execution is complete, continue to execute the logoff class and observe the dynamics of MQ.

As mentioned above, when both classes are executed in the same process, the communication between the two is fast and convenient as long as a general Function Call is adopted. Once the two classes are executed in different processes, the communication between the two cannot take the general function call channel, so we have to adopt the IPC communication channel.


3. Set IPC Communication

In the Android framework, an Application Package usually

</Pre> contains multiple Java classes, which can be executed in the same Process or in different processes. • Generally, a process only has one App. However, an App can occupy multiple processes. <P> </p> <pre code_snippet_id = "636160" snippet_file_name = "blog_20150404_2_1842967" name = "code" class = "html"> <activity android: name = ". firstActivity "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <activity android: name = ". loadActivity "> </activity> <service android: name = ". loadService "android: process =": remote "> <intent-filter> <action android: name =" com. misoo. pkm. REMOTE_SERVICE "/> </intent-filter> </service> </manifest>

Android: process = ": remote". By setting this attribute, the service is set to a separate process, which is isolated from other activities or services. In this way, there will be two processes in an app.

The FirstActivity and LoadActivity classes load the preset process. The LoadService is loaded into an independent process named "remote.


In this way, there are two independent processes on both sides of the Blue vertical line. Each process needs to create a vm object independently to ensure data security, prevents data sharing between processes, resulting in malicious data tampering, which is not conducive to program security.

Every process in Android has a VM object that executes Java code and directs JNI local program execution to implement communication between Java and C/C ++ programs.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.