Understanding AIDL Services

In the previous section, we showed you how to write an Android service that is consumed by the application that hosts the service. Now we are going to show you how to build a service that can be consumed by other processes via Remote Procedure Call (RPC). As with many other RPC-based solutions, in Android you need an Interface Definition Language (IDL) to define the interface that will be exposed to clients. In the Android world, this IDL is called Android Interface Definition Language, or AIDL. To build a remote service, you do the following:

1. Write an AIDL file that defines your interface to clients. The AIDL file uses Java syntax and has an .aidl extension.

2. Add the AIDL file to your Eclipse project. The Android Eclipse plug-in will call the AIDL compiler to generate a Java interface from the AIDL file (the AIDL compiler is called as part of the build process).

3. Implement a service and return the interface from the onBind() method.

4. Add the service configuration to your AndroidManifest.xml file. The sections that follow show you how to execute each step.

0 0

Post a comment