The Android service is divided into two types:
Local Service: The same apk is called
Remote service: Called by another apk
The remote service needs to be done with the help of Aidl.
What's aidl?
Aidl (Android Interface Definition Language) is an IDL language used to generate interprocess communication between two processes on an Android device (interprocess communication, IPC) The code. If you are in a process, such as an activity, to invoke an operation on another process (such as a service) object, you can use Aidl to generate serializable parameters.
The AIDL IPC mechanism is interface-oriented, like COM or CORBA, but more lightweight. It is the use of proxy classes to pass data on both the client and the implementation side.
The role of Aidl
Because each application runs in its own process space and can run another service process from the application UI, it often passes objects between different processes. On the Android platform, a process usually does not have access to the memory space of another process, so in order to be able to talk, the object needs to be decomposed into basic units that the operating system understands, and is ordered through the process boundary.
Using code to implement this data transfer process is tedious, and Android provides aidl tools to handle this work.
Choose the occasion of Aidl
The official documentation specifically reminds us when using aidl is necessary: Only you allow clients to access your service from different applications for interprocess communication, and to handle multithreading in your service.
If you do not need concurrent communication (IPC) between different applications, you can should create your interface by implementing a Binder, or you want to do IPC, but do not need to handle multithreading, then implement your interface using a Messenger. In any case, before using Aidl, you must understand how to bind Service--bindservice.
The following example will be given from: http://www.cnblogs.com/lonkiss/archive/2012/10/23/2735548.html
Below is a demo of the use of aidl using an instance of a client-side activity Server service to play music.
Service-side code structure
Client code structure
What is marked is the need to do it.