1. Overview: Memory cannot be shared between applications in the Android system. Therefore, interacting data between different applications (cross-process communication) is a bit trickier. 4 ways to communicate across processes are available in the Android SDK. These 4 approaches correspond to 4 application components in the Android system: Activity, Content Provider, broadcast, and service. Where activity can call other applications across processes Activity;content provider can access data in other applications (returned as cursor objects) across processes, and of course, add, delete, and change data from other applications Broadcast can send broadcasts to all applications in the Android system, while applications that require cross-process communication can listen to these broadcasts, and the service and content provider are similar and can access data in other applications, but the difference is Content provider returns a cursor object, and the service returns a Java object that can be used to communicate across processes called the Aidl service.
2.aidl (Android Interface definition Language) is an interface definition language, and the compiler generates Java code that conforms to the communication protocol through the description information of the *.aidl file, so we don't have to write this complicated code ourselves. Only need to call when needed, in this way we can complete the process of communication between the work. About the writing rules of Aidl I do not introduce more here, readers can go online to find the relevant information.
3. Four ways to access across processes:
Way One: Access activity for other applications Activity can be accessed either within the process (the same application) or across processes. If you want to access activity in the same application, you need to specify the context object and the activity's class object, with the following code:
Intent Intent = new Intent (this, test.class); StartActivity (Intent);
Cross-process access to activity is slightly different from in-process access. Although they all require intent objects, cross-process access does not need to specify the context object and the activity's class object, but instead specifies the action (a string) corresponding to the activity to be accessed. Some activity also needs to specify a URI (specified by the 2nd parameter of the intent constructor method). There are many applications in the Android system that provide the activity that can be accessed across processes, for example, the following code can directly invoke the activity that makes the call.
Intent callintent = new Intent (Intent.action_call, Uri.parse ("tel:12345678"); StartActivity (callintent);
Communication between Android processes