Analysis on AIDL for Android

current situation

Field of use

AIDL is not used frequently. There may be two reasons existing. First, the AIDL program can not be developed easily lik java program. Second, We just needn't use AIDL, in other words, we can write other simple program insteadly. 

Analysis of ViewPager

Desc of ViewPager

AIDL(Android Interface definition language), is not a controller, but a language, and you can say it as designing pattern.

AIDL is similar to other IDLs you might have worked with. It allows you to define the programming interface that both the client and service agree upon in order to communicate with each other using interprocess communication (IPC). On Android, one process cannot normally access the memory of another process. So to talk, they need to decompose their objects into primitives that the operating system can understand, and marshall the objects across that boundary for you. The code to do that marshalling is tedious to write, so Android handles it for you with AIDL.

Using AIDL is necessary only if you allow clients from different applications to access your service for IPC and want to handle multithreading in your service. If you do not need to perform concurrent IPC across different applications, you should create your interface by implementing a Binder or, if you want to perform IPC, but do not need to handle multithreading, implement your interface using a Messenger. Regardless, be sure that you understand Bound Services before implementing an AIDL.

Use of AIDL

To create a bounded service using AIDL, follow these steps:

Create the .aidl file

This file defines the programming interface with method signatures.

Implement the interface

The Android SDK tools generate an interface in the Java programming language, based on your .aidl file. This interface has an inner abstract class named Stub that extends Binder and implements methods from your AIDL interface. You must extend the Stub class and implement the methods.

Expose the interface to clients

Implement a Service and override onBind() to return your implementation of the Stub class.