http://4225953-163-com.iteye.com/blog/792997
这篇总结的不错
按照上面的文章,还是费了一些时间才调通,Remote Server的调用
主要的问题如下:
1. AndroidManifest.xml文件的写法
Server端的是在application里面加上
<service android:name=".AAA">
<intent-filter>
<action android:name="BBB"/>
</intent-filter>
</service>
其中: AAA是你自己实现的Service的子类,比如myService
BBB是用来标识一个intent的,客户端用这个标识来Bind这个Service,所以理论上任意一个唯一字符串都可以的,实际中使用aidl的类名(包括包名),这个很好理解了,首先,该类名重名的几率很小,第二个,这个aidl文件(包括整个包路径)是要公开出去的
Client端不用修改什么
2.Client端在onServiceConnected,将IBinder转换成aidl的接口,需要使用:
IXXX.Stub.asInterface(IBinder)
来转换,其中,IXXX是aidl定义的接口
我先前用强制类型转换来做,会报:
java.lang.ClassCastException: android.os.BinderProxy
的错误