当前位置:编程学习 > wap >>

急急!!aidl remote service 如何调用 Activity的方法?

aidl Activity 调用 remote service的方法这个我知道

请问:aidl remote service 如何调用 Activity的方法? --------------------编程问答-------------------- 用广播试试。在aidl里面发送广播调用。 --------------------编程问答-------------------- 还有一个方法,在你的Activity也定义一个Binder

        //activity里面的
private class MyBinder extends Binder {
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
// 你的业务逻辑
return true;
}

private void method1(){
MainActivity.this.method();
}
}

public void method() {
//业务逻辑
}



ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
}

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
binder1 = new MyBinder();
Parcel p1 = Parcel.obtain();
Parcel p2 = Parcel.obtain();
p1.writeStrongBinder(binder1);
try {
service.transact(0, p1, p2, 0); //传入到你的aidl service中。
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};


--------------------编程问答-------------------- 意思也就是把Activity定义的Binder传到Service里面,这样Service就能获得Activity实例,
也就能间接的调用到Activity里面的方法了。
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,