/******************************************************************************** * Android OID aidl automatically generate Java file Test * Description: * Know that there is aidl this thing has been a long time, but has not taken the moment to systematically understand its working mechanism, now * take a moment to 1.1 points to verify its function. * 2016-5-8 Shenzhen Nanshan Ping Shan village Zengjianfeng ************************************************ *******************************/First, reference article:1. Android Aidl Use detailed http://blog.csdn.net/stonecao/article/details/6425019 2. Android interprocess communication: Using Aidl http://blog.csdn.net/saintswordsman/article/details/5130947Second, cat forservice.aidl package com.example.aidltest.aidl; Import com.example.aidltest.aidl.forActivity; InterfaceForservice {voidRegistertestcall (foractivity CB); voidInvokcallback (); } III, Cat Forservice.java/** This file is auto-generated. Do not MODIFY. * Original File:d:\\soft\\android\\workspace\\aidltest\\src\\com\\example\\aidltest\\aidl\\forservice.aidl*/Package Com.example.aidltest.aidl; //inherits the Android.os.IInterface interface Public InterfaceForservice extends Android.os.IInterface {/** Local-side IPC implementation stub class.*/ //The stub class inherits the binder and inherits the interfaces we defined in the Aidl file . Public Static Abstract classStub extends Android.os.Binder implements Com.example.aidltest.aidl.forService {Private StaticFinal Java.lang.String descriptor ="Com.example.aidltest.aidl.forService"; /** Construct The stub at attach it to the interface.*/ PublicStub () { This. Attachinterface ( This, descriptor); } /** * Cast an IBinder object to an com.example.aidltest.aidl.forService * interface, Generatin G A proxy if needed. */ //You will often see this part of the content when you use it . Public Staticcom.example.aidltest.aidl.forService asinterface (Android.os.IBinder obj) {if(obj = =NULL)) { return NULL; } android.os.IInterface iin=Obj.querylocalinterface (descriptor); if(((Iin! =NULL) &&(iin instanceof Com.example.aidltest.aidl.forService))) { return((Com.example.aidltest.aidl.forService) iin); } return Newcom.example.aidltest.aidl.forService.Stub.Proxy (obj); } @Override PublicAndroid.os.IBinder Asbinder () {return This; } @Override PublicBoolean Ontransact (intcode, Android.os.Parcel data, android.os.Parcel reply,intflags) throws Android.os.RemoteException {Switch(code) { Caseinterface_transaction: {reply.writestring (descriptor); return true; } CaseTransaction_registertestcall: {data.enforceinterface (descriptor); Com.example.aidltest.aidl.forActivity _arg0; _arg0=com.example.aidltest.aidl.forActivity.Stub. Asinterface (Data.readstrongbinder ()); This. Registertestcall (_ARG0); Reply.writenoexception (); return true; } Casetransaction_invokcallback: {data.enforceinterface (descriptor); This. Invokcallback (); Reply.writenoexception (); return true; } } returnsuper.ontransact (Code, data, reply, flags); } Private Static classProxy implements Com.example.aidltest.aidl.forService {PrivateAndroid.os.IBinder Mremote; Proxy (Android.os.IBinder remote) {mremote=remote; } @Override PublicAndroid.os.IBinder Asbinder () {returnMremote; } Publicjava.lang.String Getinterfacedescriptor () {returndescriptor; } @Override Public voidRegistertestcall (com.example.aidltest.aidl.forActivity CB) throws Android oid.os.RemoteException {android.os.Parcel _data=Android.os.Parcel.obtain (); Android.os.Parcel _reply=Android.os.Parcel.obtain (); Try{_data.writeinterfacetoken (descriptor); _data.writestrongbinder ( ((CB!=NULL)) ?(Cb.asbinder ()): (NULL))); Mremote.transact (Stub.transaction_registertestcall, _data, _reply,0); _reply.readexception (); } finally{_reply.recycle (); _data.recycle (); }} @Override Public voidInvokcallback () throws android.os.RemoteException {Android.os.Parcel _data=Android.os.Parcel.obtain (); Android.os.Parcel _reply=Android.os.Parcel.obtain (); Try{_data.writeinterfacetoken (descriptor); Mremote.transact (Stub.transaction_invokcallback, _data, _reply,0); _reply.readexception (); } finally{_reply.recycle (); _data.recycle (); } } } StaticFinalintTransaction_registertestcall = (Android.os.IBinder.FIRST_CALL_TRANSACTION +0); StaticFinalintTransaction_invokcallback = (Android.os.IBinder.FIRST_CALL_TRANSACTION +1); } //custom methods in Aidl, not implemented Public voidRegistertestcall (com.example.aidltest.aidl.forActivity cb) throws Android.os.RemoteException; Public voidInvokcallback () throws android.os.RemoteException; } Four, Cat Mainactivity.java Public classMainactivity extends Actionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {...Newforservice.stub () {@Override Public voidRegistertestcall (foractivity cb) throws RemoteException {//TODO auto-generated Method Stub} @Override Public voidInvokcallback () throws RemoteException {//TODO auto-generated Method Stub } }; ...... } }
Android aidl automatically generate Java file test