AIDL与其他IDL语言类似,你需要做一些工作。 它允许你定义客户端与服务端达成一致的程序接口使用进程间通信相互交流。 在ANdroid上面,一个进程不能正常的访问另一个进程的内存。 所以说,他们需要分解他们的对象为操作系统可以理解的基本单位,然后为你把这些对象按次序跨越进程边界 书写这些代码是单调冗长的,所以android使用AIDL为你处理这个问题。

注意:使用AIDL只有在你允许来自不同应用的客户端跨进程通信访问你的service,并且想要在你的service种处理多线程的时候才是必要的。 如果你不需要执行不同应用之间的IPC并发,你应该通过实现Binder建立你的接口,或者如果你想执行IPC,但是不需要处理多线程。那么使用Messenger实现你的接口 不管怎样,确保你在实现一个AIDL之前理解了Bound Service

在你设计你的AIDL接口之前,请注意调用一个AIDL接口是直接的函数调用 你不应该假设线程在哪个调用中发生 情形与依赖调用是来自一个本地进程中的线程还是一个远程进程中的线程相关 尤其是:

  • 来自本地进程的调用与调用者在同一个线程中执行。 如果这是你的主UI线程,线程继续在AIDL接口中执行 如果是其他的线程,则它是一个在service中执行你的代码的线程 这样,如果只是本地线程访问这个service,你完全可以控制哪些线程在其中执行(但是如果是那样的话,那么你压根就不应该使用AIDL,而应该通过实现Binder建立接口)
  • 平台在你自己的进程中内部维护一个线程池中分配的远程进程的调用 你必须为从未知线程发出的即将到来的调用,并且是伴随同时多个调用做好准备 换句话说,AIDL接口的实现必须是完全的线程安全的
  • 单向关键词限定了远程调用的行为 使用的时候,一个远程调用不会被阻塞;它只是简单的发送传输数据并且立即返回 最终接口的实现把它作为一个来自Binder线程池的常规调用、一个普通的远程调用来接收 如果本地调用使用单向的,那么就不会有影响,并且调用仍然是异步的

定义一个AIDL接口

你必须在一个.aidl文件中使用java编程语言语法定义你的AIDL接口,然后在提供service的应用中和任何绑定到这个service的应用中的源代码中(在src目录吓)保存它

当你编译包含.aidl文件的应用时,Android SDK工具基于这个.aidl文件生成一个IBinder接口,并且把它保存到项目的gen目录吓 service必须恰当的实现这个IBinder接口 之后客户端应用可以绑定到这个服务上,然后从IBinder调用方法来执行IPC

使用AIDL建立一个邻接的service需要遵循下面的步骤

  1. 1.建立.aidl文件

    这个文件使用方法签名定义了语言接口

  2. 2.实现这个接口

    Android SDk工具基于你的.aidl文件使用java语言生成一个接口 这个接口有一个内部抽象类,叫做Stub,它是继承Binder并且实现你AIDL接口的 你必须继承这个Stub类并且实现这些方法

  3. 3.暴露这个接口给客户端

    实现一个service并且覆盖onBind()方法返回你的Stub实现类

警告:在你第一次发布AIDL之后的其中任何的改变必须保持向后兼容来避免破坏其他应用程序使用你的service 也就是说,因为你的.aidl文件必须被复制到其他应用程序中来让他们访问你service的接口,你必须维护原始接口的支持。

1.建立.aidl文件

AIDL使用一个简单的语法让你声明一个带有一个或者多个带有参数和返回值方法的接口 参数和返回值可以是任何类型,甚至是AIDL生成的接口

你必须使用java语言构建.aidl文件 每一个.aidl文件必须定义一个简单的接口并且要求只有接口声明和方法签名

默认的,AIDL支持下面数据类型:

  • ava语言中的所有基本数据类型(比如int、long、char、boolean等等)
  • String
  • CharSequence
  • List

    List中的所有元素必须是AIDL支持的类型之一,或者是一个其他AIDL生成的接口,或者是你定义的parcelable List可以使用范型(例如,List) 接收端的实际类经常是一个ArrayList,尽管方法是使用List接口生成的

  • Map

    Map中的所有元素必须是AIDL支持的类型之一,或者是一个其他AIDL生成的接口,或者是你定义的parcelable 范型map是不被支持的(比如这种形式Map) 接收端的实际类经常是一个HashMap,尽管方法是使用Map接口生成的

对于上述类型之外的类型,你必须声明import,即使在同一个包内。

当定义你的service接口的时候,注意:

  • 方法可以接收0或多个参数,并且有返回值或者返回void
  • 所有非基本数据类型要求要求一个定向的tag来指定数据是去往哪个方向的 无论是输入、输出,还是输入输出(参加下面的例子) 基本数据类型是默认支持的,并且不能是其他的。

    警告:你应该限制方向于真正需要的地方,因为排列整理参数的开销是很昂贵的。

  • .aidl文件中的所有的代码注释都在生成的IBinder接口中(除了在import和包声明之前的注释)
  • 只支持方法,你不可以在AIDL暴露静态域

这有个.aidl文件的例子:

// IRemoteService.aidlpackage com.example.android;// Declare any non-default types here with import statements/** Example service interface */interface IRemoteService {    /** Request the process ID of this service, to do evil things with it. */    int getPid();    /** Demonstrates some basic types that you can use as parameters     * and return values in AIDL.     */    void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,            double aDouble, String aString);}

简单的保存你的.aidl文件在你工程的src目录下,当你build你的应用时,SDK工具在你工程的gen目录下生成IBinder接口文件 生成的文件名字与.aidl名字匹配,但是是以.java为扩展名(例如IRemoteService.aidl对应为IRemoteService.java)

如果你使用Eclipse,增量编译几乎是立刻生成binder类。如果你不使用Eclipse,那么Ant工具在你下次编译你的应用(你应该使用ant debug或者ant release编译你的工程)时生成binder类。一旦你写好了.aidl文件,你的代码就可以链接到生成的类上面了。

2.实现接口

当你编译你的应用时,Android SDK工具生成一个.java接口文件用你的.aidl文件命名 生成的接口包含一个名字为Stub的子类(比如YourInterface.Stub),这是一个它父类的抽象实现,并且声明了.aidl中所有的方法

注意:Stub也定义了一些辅助的方法,最显著的就是asInterface(),它是用来接收一个IBinder(通常IBinder传递给客户端的onServiceConnected()回调方法)并且返回一个Stub接口的实例 更多细节参考Calling an IPC Method章节。

为了实现来自.aidl文件生成的接口,需要继承Binder接口(例如YourInterface.Stub)并且实现从.aidl文件中继承的方法。

这有一个使用匿名实例实现一个叫IRemoteService(定义在IRemoteService.aidl中,例子如上)的接口的例子

private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {    public int getPid(){        return Process.myPid();    }    public void basicTypes(int anInt, long aLong, boolean aBoolean,        float aFloat, double aDouble, String aString) {        // Does nothing    }};

mBinder是一个Stub类的实例

当实现你的AIDL接口的时候有很多规则需要注意

  • 调用不保证在主线程中执行,所以你需要一开始就考虑多线程并且适当的build你的service为线程安全的
  • 默认的,RPC调用是同步的。 如果你知道service需要花费一些时间来完成请求,你就不应该从activity的主线程中调用它,因为它可能使得应用没有响应(Android也许会显示一个ANR的对话框),通常你应该在客户端中一个单独的线程调用它
  • 抛出的异常不会返回给调用者

3.暴露接口给客户端

一旦你为service实现了接口,你需要把它暴露给客户端,这样他们才能绑定到上面 为了给你的service暴露接口,继承Service并且实现onBind()方法返回一个你实现生成的Stub类(像我们在上一结讨论的那样) 这有一个service暴露IRemoteService接口给客户端的例子

public class RemoteService extends Service {    @Override    public void onCreate() {        super.onCreate();    }    @Override    public IBinder onBind(Intent intent) {        // Return the interface        return mBinder;    }    private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {        public int getPid(){            return Process.myPid();        }        public void basicTypes(int anInt, long aLong, boolean aBoolean,            float aFloat, double aDouble, String aString) {            // Does nothing        }    };}

现在,当一个客户端(比如一个activity)调用bindService()来连接到这个service,这个客户端的onServiceConnected()回调函数接收service中onBind()方法返回的mBinder实例

客户端必须可以访问接口类,所以如果客户端和服务端在不同的应用中,那么客户端所在的应用必须有一份.aidl文件的副本在其src目录下(生成android.os.Binder接口,提供客户端访问AIDL方法都在这个目录下)

当客户端在onServiceConnected()回调方法中接收到IBinder时,它必须调用你的ServiceInterface.Stub.asInterface(service)来把返回参数映射到你的ServiceInterface类型上。例如:

IRemoteService mIRemoteService;private ServiceConnection mConnection = new ServiceConnection() {    // Called when the connection with the service is established    public void onServiceConnected(ComponentName className, IBinder service) {        // Following the example above for an AIDL interface,        // this gets an instance of the IRemoteInterface, which we can use to call on the service        mIRemoteService = IRemoteService.Stub.asInterface(service);    }    // Called when the connection with the service disconnects unexpectedly    public void onServiceDisconnected(ComponentName className) {        Log.e(TAG, "Service has unexpectedly disconnected");        mIRemoteService = null;    }};

更多样本代码参见ApiDemos中的RemoteService.java

跨进程传递对象

如果你想通过IPC接口把一个类从一个进程传递到另一个进程中,那么是可以的。 然而,你必须保证为你的类而写的代码也是对IPC通道另一端是可用的,并且你的类必须支持Parcelable接口 支持Parcelable接口是很重要的,因为它允许Android系统把对象分解为可以被组织跨进程传输基本单元

为了建立一个支持Parcelable协议的类,你必须遵守下面的规则:

  1. 要实现Parcelable接口
  2. 实现writeToParcel,它是用来把对象的当前状态写入到一个Parcel对象中的。
  3. 在你的类中添加一个叫CREATOR的静态域,它要实现Parcelable.Creator接口
  4. 最后,建立一个.aidl文件声明你的parcelable类(如下面的Rect.aidl所示)

    如果你使用一个定制的构建过程,不要构建.aidl文件。与C语言中的头文件类似,.aidl文件不会被编译

AIDL使用代码中的这些域和方法封装传送和解读你的对象

例如,这有一个Rect.aidl文件类建立一个Rect类,它是parcelable的

package android.graphics;// Declare Rect so AIDL can find it and knows that it implements// the parcelable protocol.parcelable Rect;

这有一个Rect类如何实现Parcelable协议的例子

import android.os.Parcel;import android.os.Parcelable;public final class Rect implements Parcelable {    public int left;    public int top;    public int right;    public int bottom;    public static final Parcelable.Creator<Rect> CREATOR = newParcelable.Creator<Rect>() {        public Rect createFromParcel(Parcel in) {            return new Rect(in);        }        public Rect[] newArray(int size) {            return new Rect[size];        }    };    public Rect() {    }    private Rect(Parcel in) {        readFromParcel(in);    }    public void writeToParcel(Parcel out) {        out.writeInt(left);        out.writeInt(top);        out.writeInt(right);        out.writeInt(bottom);    }    public void readFromParcel(Parcel in) {        left = in.readInt();        top = in.readInt();        right = in.readInt();        bottom = in.readInt();    }}

在Rect类中组织传送数据是很简单的 看一下Parcel上面的其他函数,看看你可以如何将其他类型的值写入一个Parcel中。

警告:不要忘记从其他进程接收数据的安全本质性 这种情况下,Rect从Parcel中读取4个数字,但是这取决于你要保证他们在可接收范围之内而不管调用者到底试图要做些什么 获取更多关于如何远离恶意程序保证你应用安全的更多信息,参见Security and Permissions

调用一个IPC方法

下面是调用步骤,调用者必须调用一个AIDL定义的远程接口

  1. 在项目中的src目录下面导入.aidl文件
  2. 声明一个IBinder接口(基于AIDL生成的)的实例
  3. 实现ServiceConnection
  4. 调用Context.bindService(),传递到你的ServiceConnection实现中。
  5. 在你的onServiceConnected()实现中,你会收到一个IBinder实例(称为服务端) 调用YourInterfaceName.Stub.asInterface((IBinder)service)把返回值映射到YourInterface类型上面
  6. 调用你接口中定义的方法 你应该捕获当连接损坏时抛出的DeadObjectException异常,这是远程方法唯一会抛出的异常
  7. 使用你接口的实例调用Context.unbindService()来断开连接

调用IPC服务端的一些注释:

  • 对象跨进程时是引用计数的
  • 你可以传递一个匿名对象作为方法的参数

更多绑定service的信息请阅读Bound Services文档

调用一个AIDL建立的服务端的一些样本代码,来自ApiDemos工程中的Remote Service样本。

public static class Binding extends Activity {    /** The primary interface we will be calling on the service. */    IRemoteService mService = null;    /** Another interface we use on the service. */    ISecondary mSecondaryService = null;    Button mKillButton;    TextView mCallbackText;    private boolean mIsBound;    /**     * Standard initialization of this activity.  Set up the UI, then wait     * for the user to poke it before doing anything.     */    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.remote_service_binding);        // Watch for button clicks.        Button button = (Button)findViewById(R.id.bind);        button.setOnClickListener(mBindListener);        button = (Button)findViewById(R.id.unbind);        button.setOnClickListener(mUnbindListener);        mKillButton = (Button)findViewById(R.id.kill);        mKillButton.setOnClickListener(mKillListener);        mKillButton.setEnabled(false);        mCallbackText = (TextView)findViewById(R.id.callback);        mCallbackText.setText("Not attached.");    }    /**     * Class for interacting with the main interface of the service.     */    private ServiceConnection mConnection = new ServiceConnection() {        public void onServiceConnected(ComponentName className,                IBinder service) {            // This is called when the connection with the service has been            // established, giving us the service object we can use to            // interact with the service.  We are communicating with our            // service through an IDL interface, so get a client-side            // representation of that from the raw service object.            mService = IRemoteService.Stub.asInterface(service);            mKillButton.setEnabled(true);            mCallbackText.setText("Attached.");            // We want to monitor the service for as long as we are            // connected to it.            try {                mService.registerCallback(mCallback);            } catch (RemoteException e) {                // In this case the service has crashed before we could even                // do anything with it; we can count on soon being                // disconnected (and then reconnected if it can be restarted)                // so there is no need to do anything here.            }            // As part of the sample, tell the user what happened.            Toast.makeText(Binding.this, R.string.remote_service_connected,                    Toast.LENGTH_SHORT).show();        }        public void onServiceDisconnected(ComponentName className) {            // This is called when the connection with the service has been            // unexpectedly disconnected -- that is, its process crashed.            mService = null;            mKillButton.setEnabled(false);            mCallbackText.setText("Disconnected.");            // As part of the sample, tell the user what happened.            Toast.makeText(Binding.this, R.string.remote_service_disconnected,                    Toast.LENGTH_SHORT).show();        }    };    /**     * Class for interacting with the secondary interface of the service.     */    private ServiceConnection mSecondaryConnection = new ServiceConnection() {        public void onServiceConnected(ComponentName className,                IBinder service) {            // Connecting to a secondary interface is the same as any            // other interface.            mSecondaryService = ISecondary.Stub.asInterface(service);            mKillButton.setEnabled(true);        }        public void onServiceDisconnected(ComponentName className) {            mSecondaryService = null;            mKillButton.setEnabled(false);        }    };    private OnClickListener mBindListener = new OnClickListener() {        public void onClick(View v) {            // Establish a couple connections with the service, binding            // by interface names.  This allows other applications to be            // installed that replace the remote service by implementing            // the same interface.            bindService(new Intent(IRemoteService.class.getName()),                    mConnection, Context.BIND_AUTO_CREATE);            bindService(new Intent(ISecondary.class.getName()),                    mSecondaryConnection, Context.BIND_AUTO_CREATE);            mIsBound = true;            mCallbackText.setText("Binding.");        }    };    private OnClickListener mUnbindListener = new OnClickListener() {        public void onClick(View v) {            if (mIsBound) {                // If we have received the service, and hence registered with                // it, then now is the time to unregister.                if (mService != null) {                    try {                        mService.unregisterCallback(mCallback);                    } catch (RemoteException e) {                        // There is nothing special we need to do if the service                        // has crashed.                    }                }                // Detach our existing connection.                unbindService(mConnection);                unbindService(mSecondaryConnection);                mKillButton.setEnabled(false);                mIsBound = false;                mCallbackText.setText("Unbinding.");            }        }    };    private OnClickListener mKillListener = new OnClickListener() {        public void onClick(View v) {            // To kill the process hosting our service, we need to know its            // PID.  Conveniently our service has a call that will return            // to us that information.            if (mSecondaryService != null) {                try {                    int pid = mSecondaryService.getPid();                    // Note that, though this API allows us to request to                    // kill any process based on its PID, the kernel will                    // still impose standard restrictions on which PIDs you                    // are actually able to kill.  Typically this means only                    // the process running your application and any additional                    // processes created by that app as shown here; packages                    // sharing a common UID will also be able to kill each                    // other's processes.                    Process.killProcess(pid);                    mCallbackText.setText("Killed service process.");                } catch (RemoteException ex) {                    // Recover gracefully from the process hosting the                    // server dying.                    // Just for purposes of the sample, put up a notification.                    Toast.makeText(Binding.this,                            R.string.remote_call_failed,                            Toast.LENGTH_SHORT).show();                }            }        }    };    // ----------------------------------------------------------------------    // Code showing how to deal with callbacks.    // ----------------------------------------------------------------------    /**     * This implementation is used to receive callbacks from the remote     * service.     */    private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {        /**         * This is called by the remote service regularly to tell us about         * new values.  Note that IPC calls are dispatched through a thread         * pool running in each process, so the code executing here will         * NOT be running in our main thread like most other things -- so,         * to update the UI, we need to use a Handler to hop over there.         */        public void valueChanged(int value) {            mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, value, 0));        }    };    private static final int BUMP_MSG = 1;    private Handler mHandler = new Handler() {        @Override public void handleMessage(Message msg) {            switch (msg.what) {                case BUMP_MSG:                    mCallbackText.setText("Received from service: " + msg.arg1);                    break;                default:                    super.handleMessage(msg);            }        }    };}

1.基于前面写的aidl使用,这段时间准备研究ActivityManager框架,对aidl进行了更深入的研究,因为android框架大量使用了进程通信机制,所以,在研究android framework前认真研究一下AIDL的实现机制十分有必要的

2.前面讲了aidl是 Android Interface definition language的缩写,它是一种进程通信接口的描述,通过sdk解释器对器进行编译,会把它编译成java代码在gen目录下,类路径与aidl文件的类路径相同。

3.aidl接口
package com.cao.android.demos.binder.aidl;
import com.cao.android.demos.binder.aidl.AIDLActivity;
interface AIDLService {
void registerTestCall(AIDLActivity cb);
void invokCallBack();
}

它编译后生成的java文件如下

AIDLService.java详细描述了aidl接口的实现,看上面图示,AIDLActivity.aidl编译成了一个接口AIDLActivity,一个存根类Stub,一个代理类Proxy
public interface AIDLService extends android.os.IInterface//与AIDLActivity.aidl中定义的接口对应的java接口实现
public static abstract class Stub extends android.os.Binder implements com.cao.android.demos.binder.aidl.AIDLService
//继承android.os.Binder,在onTransact完成对通信数据的接收,通过不同通信参数code调用AIDLService接口方法,并回写调用返回结果AIDLService接口方法需要在
//服务端实现
private static class Proxy implements com.cao.android.demos.binder.aidl.AIDLService
//实现AIDLService接口方法,但是方法只是执行代理远程调用操作,具体方法操作在远端的Stub存根类中实现

总的来说,AIDLActivity.aidl编译会生成一个AIDLActivity接口,一个stub存根抽像类,一个proxy代理类,这个实现其实根axis的wsdl文件编译生成思路是一致的,
stub存根抽像类需要在服务端实现,proxy代理类被客户端使用,通过stub,proxy的封装,屏蔽了进程通信的细节,对使用者来说就只是一个AIDLActivity接口的调用

4.根据以上思路使用aidl再看一下AIDLService调用实现代码
--1.在服务端实现AIDLService.Stub抽象类,在服务端onBind方法中返回该实现类
--2.客户端绑定service时在ServiceConnection.onServiceConnected获取onBind返回的IBinder对象
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
Log("connect service");
mService = AIDLService.Stub.asInterface(service);
try {
mService.registerTestCall(mCallback);
} catch (RemoteException e) {

}
}
注意mConnection在bindservice作为调用参数:bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
--3.AIDLService.Stub.asInterface(service);
public static com.cao.android.demos.binder.aidl.AIDLService asInterface(android.os.IBinder obj)
{
if ((obj==null)) {
return null;
}
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
//如果bindService绑定的是同一进程的service,返回的是服务端Stub对象本省,那么在客户端是直接操作Stub对象,并不进行进程通信了
if (((iin!=null)&&(iin instanceof com.cao.android.demos.binder.aidl.AIDLService))) {
return ((com.cao.android.demos.binder.aidl.AIDLService)iin);
}
//bindService绑定的不是同一进程的service,返回的是代理对象,obj==android.os.BinderProxy对象,被包装成一个AIDLService.Stub.Proxy代理对象
//不过AIDLService.Stub.Proxy进程间通信通过android.os.BinderProxy实现
return new com.cao.android.demos.binder.aidl.AIDLService.Stub.Proxy(obj);
}
--4.调用AIDLService接口方法,如果是同一进程,AIDLService就是service的Stub对象,等同直接调用Stub对象实现的AIDLService接口方法
如果是一个proxy对象,那就是在进程间调用了,我们看一个客户端调用的例子:
public void onClick(View v) {
Log("AIDLTestActivity.btnCallBack");
try {
mService.invokCallBack();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
--mService.invokCallBack()等同调用Proxy.invokCallBack,这个时候是进程间调用,我们看代理方法的实现
public void invokCallBack() throws android.os.RemoteException
{
//构造一个Parcel对象,该对象可在进程间传输
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
try {
//DESCRIPTOR = "com.cao.android.demos.binder.aidl.AIDLService",描述了调用哪个Stub对象
_data.writeInterfaceToken(DESCRIPTOR);
//Stub.TRANSACTION_invokCallBack 标识调用Stub中哪个接口方法,mRemote在是构造Proxy对象的参数obj,也就是public void onServiceConnected(ComponentName className, IBinder service)
//中的service参数,它是一个BinderProxy对象,负责传输进程间数据。
mRemote.transact(Stub.TRANSACTION_invokCallBack, _data, _reply, 0);
_reply.readException();
}
finally {
_reply.recycle();
_data.recycle();
}
}
--5.BinderProxy.transact 该方法本地化实现
public native boolean transact(int code, Parcel data, Parcel reply,
int flags) throws RemoteException;
//对应实现的本地化代码 /frameworks/base/core/jni/android_util_Binder.cpp->static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj,
jint code, jobject dataObj,
jobject replyObj, jint flags)
//具体进程通信在c代码中如何实现,以后再深入研究。
--6.服务端进程数据接收
--调用堆栈
##AIDLService.Stub.onTransact
##AIDLService.Stub(Binder).execTransact
##NativeStart.run
--AIDLService.Stub.onTransact
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
{
switch (code)
{
case INTERFACE_TRANSACTION:
{
reply.writeString(DESCRIPTOR);
return true;
}
case TRANSACTION_registerTestCall:
{
data.enforceInterface(DESCRIPTOR);
com.cao.android.demos.binder.aidl.AIDLActivity _arg0;
_arg0 = com.cao.android.demos.binder.aidl.AIDLActivity.Stub.asInterface(data.readStrongBinder());
this.registerTestCall(_arg0);
reply.writeNoException();
return true;
}
//TRANSACTION_invokCallBack由前面客户端调用的时候transact方法参数决定,code==TRANSACTION_invokCallBack,执行
//invokCallBack方法,方法由继承Stud的服务端存根类实现。
case TRANSACTION_invokCallBack:
{
data.enforceInterface(DESCRIPTOR);
this.invokCallBack();
reply.writeNoException();
return true;
}

5.里面设置本地C代码的调用,我没有深入研究,随着后面我对android框架的深入,我会发blog进一步说民底层C代码是如何实现进程通信的,关于AIDL进程通信,暂时研究到这里。

原文:http://blog.csdn.net/stonecao/article/details/6579333

更多相关文章

  1. 安卓开发中调用WebService实例
  2. 【专访】爱图腾高级架构师 李鹏军:手机音频接口具有无限的应用潜
  3. Service与Android系统实现(1)-- 应用程序里的Service(二)
  4. Android几种Service常驻内存的小思路
  5. Android(安卓)studio 3.6 NDK开发 基本流程入门了解
  6. Android(安卓)数据持久化(一)之简单数据持久化
  7. ANDROID Bionic C DOCS
  8. android 4.0以上WebView不能全屏播放视频的解决办法
  9. 【全】Android官网MediaPlayer章节翻译与总结(下)

随机推荐

  1. android 机顶盒Launcher开发
  2. android应用程序制定皮肤
  3. Android更换RatingBar图片
  4. Android日志服务例子,将日志保存在文件中
  5. Android (滑动屏幕切换图片的实现)
  6. Android(安卓)系统固定Launcher的方法
  7. Android之获取、设置EditText的文本
  8. android数据库升级的措辞
  9. Android8.1隐藏状态栏电池图标
  10. Android如何拦截WebView之中的Post或者Ge