使用代理对象实现AIDL接口
Class studyManager = Class.forName("StudyManager");
Class iStudyCallbackClient = Class.forName("IStudyCallbackClient");
Method setTouchCallback = studyManager.getDeclaredMethod("setTouchCallback", iStudyCallbackClient);
Proxy proxy = (Proxy) Proxy.newProxyInstance(iStudyCallbackClient.getClassLoader(),
new Class[] { iStudyCallbackClient }, new IStudyCallbackClientImpl());
setTouchCallback.invoke(studyManager.newInstance(), proxy);
class IStudyCallbackClientImpl implements InvocationHandler {
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
Log.d(TAG, method.getName());//why here is asBinde() not sendPoint()?
return null;
}
AIDL
interface IStudyCallbackClient {
void sendPoint(int x,int y);
}
代码运行正常。
当调用回调函数(IStudyCallbackClient.sendPoint(int x,int y))时,
为什么method.getName()是asBinder?而不是sendPoint()?
答案 0 :(得分:0)
错误是JDK的代理依赖接口。 args是抽象类,它实现了接口,而不仅仅是接口。
我首先认为接口args是这样的:
public void setTouchCallback(ICallback mICallback)
但是真正的参数就像这样
public static abstract class Stub extends android.os.Binder implements ICallback