aidl跨进程通信中callback为空,原因如下:
1.callback后面没有带stub
2.是Callback中实现了asBinder导致的
如下是修改前的代码
try {
mFingerViewModel.openDevice(new ICallback() {
@Override
public IBinder asBinder() {
return null;
}
@Override
public void onSuccess(int result) throws RemoteException {
}
@Override
public void onFailure(String errorMsg) throws RemoteException {
}
});
} catch (RemoteException e) {
throw new RuntimeException(e);
}
如下是修改后的代码:
try {
aidlInterface.start(new ICallback.Stub() {
@Override
public void onSuccess(int result) throws RemoteException {
Log.d(TAG, "onSuccess: " + result);
}
@Override
public void onFailure(String errorMsg) throws RemoteException {
Log.d(TAG, "onFailure:" + errorMsg);
}
});
Log.d("AIDL", "Result: "); // 输出 5
} catch (RemoteException e) {
e.printStackTrace();
}