原文地址:http://blog.csdn.net/chenfeng0104/article/details/6989217
在上一篇文章(Service使用方式)中,介绍了Android进程间通信(IPC,即不同APP间通信)的使用,并给出了一个示例。但并没有深入分析aidl是怎样可以做到进程间通信的,它的执行过程是怎样的?
这篇文章来分析IRemoteService.aidl的执行过程,并理解aidl是怎样跨进程通信的。
当我们创建IRemoteService.aidl文件时,IDE会为我们在gen目录中创建相应的文件。
- /** This file is auto-generated. DO NOT MODIFY.
- * Original file: F:\\workspace\\AndroidImprove\\src\\com\\example\\aidl\\IRemoteService.aidl
- */
- package com.example.aidl;
- public interface IRemoteService extends android.os.IInterface
- {
- /** Local-side IPC implementation stub class. */
- public static abstract class Stub extends android.os.Binder implements com.example.aidl.IRemoteService
- {
- private static final java.lang.String DESCRIPTOR = "com.example.aidl.IRemoteService";
- /** Construct the stub at attach it to the interface. */
- public Stub()
- {
- this.attachInterface(this, DESCRIPTOR);
- }
- /**
- * Cast an IBinder object into an com.example.aidl.IRemoteService interface,
- * generating a proxy if needed.
- */
- public static com.example.aidl.IRemoteService asInterface(android.os.IBinder obj)
- {
- if ((obj==null)) {
- return null;
- }
- android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
- if (((iin!=null)&&(iin instanceof com.example.aidl.IRemoteService))) {
- return ((com.example.aidl.IRemoteService)iin);
- }
- return new com.example.aidl.IRemoteService.Stub.Proxy(obj);
- }
- public android.os.IBinder asBinder()
- {
- return this;
- }
- @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
- {
- switch (code)
- {