Android AIDL Concept Charlie Tsai @ Android Study Group
Charlie Tsai @ Android Study Group [email protected] Software Engineer
Agenda Introduction of AIDL Write your AIDL files Implementation of AIDL
Introduction of AIDL
?AIDL? Android Interface Definition Language Main approach is IPC (Inter-Process Communication) Support types: All primitive types, CharSequence & String, List & Map, Parcelable class
IPC Issue Memories of Process A Process B of Process B X Cannot Access (Memory protection by Kernel)
How AIDL solve IPC issue Memories of Process A Process B of Process B Linux Kernel & Binder Driver Access Access
Write Your AIDL File Write *.aidl for your AIDL interface You can turn your Parcelable Class into AIDL Include if you use Other AIDL class/interface Note: List will become ArrayList in another side Map will become HashMap in another side (WHY?)
AIDL Data Structure MyData.java MyData.aidl
AIDL Interface IMyAidlInterface.aidl
How Parcelable Work
String int Data in memory (order is matter)
Usages of AIDL
Export Your Service Allow to be bound by other App.
Use Other’s Service Copy *.aidl file into your project (Because you need to know this Interface)
Generated File by AIDL
I Interface: Basic interface can be used for IPC android.os.IBinder: Core class of IPC Use YourInterface.asInterface(IBinder) to case IBinder to YourInterface. Use IBinder.queryLocalInterface() to know if this IBinder is in local or remote. If IBinder is in local, call function directly. If IBinder is a remote object, use transact and parcel to call function. Let’s see the source code…