我做的项目中有两个aidl文件,一个是Service,一个是Callback,Service供第三方应用调用,因为返回数据是异步的,所以加了个callback,但第三方应用在注册callback后,我这边判空发现收到的callback为空,在网上查了下,各种鸡肋方法真的无语到死,比如有一个博客里说:客户端不要重写asBinder或者不返回null…侮辱智商的博客… 你继承或直接new这个callback给我不重写看看? 真想喷他~
接下来直接步入正题,客户端注册callback到服务端时,传的callback一定要传calllback.Stub,具体为什么,自己总结下源码就好了
ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
ss = ISoundService.Stub.asInterface(iBinder);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
ss = null;
}
};
try {
ss.registerCallback(new ISoundEffectCallback.Stub() {
@Override
public void notify(String cmd, int result) throws RemoteException {
//代码块
}
});
} catch (RemoteException e) {
e.printStackTrace();
}