android aidl继承stub,android - AIDL: Stub class methods not being called - Stack Overflow

I am using AIDL to pass objects from an Activity to a Service and am getting some strange behavior. To my understanding, the idea behind AIDL is to create an interface in a .aidl file, which android will then implement (partially) in a dynamically generated class. Android will create an abstract class called Stub, which you then need to instantiate and add the implementation of the methods which you defined in your .aidl interface. Once all of that is in place, the remote service can be instantiated, and the methods declared in the .aidl interface file (and defined in your instantiation of the Stub class) can be called.

That is my impression of how this mechanism works, however when I tried implementing it, I notice that the definitions for the methods I declared in the Stub class are not being run; instead what is being run is IBinder.transct()

Here is a snippet of what I'm trying to do:

This is implemented in my Service:

public final INetService.Stub mBinder = new INetService.Stub() {

public void sendInteger(String ID, int data) throws RemoteException {

// TODO Auto-generated method stub

}

public void sendString(String ID, String data) throws RemoteException {

ServiceConnectionHandler connHandler = new ServiceConnectionHandler(ID, data);

}

public void sendObject(String ID, NetMessage data) throws RemoteException {

ServiceConnectionHandler connHandler = new ServiceConnectionHandler(ID, data.getData());

}

};

And this is inside my Activity, which tries to use and talk to the service:

private INetService mService = null;

private NetServiceConnection conn = null;

class NetServiceConnection implements ServiceConnection

{

public void onServiceConnected(ComponentName name, IBinder service) {

mService = INetService.Stub.asInterface(service);

Log.d( "ADDERSERVICECLIENT","onServiceConnected" );

}

@Override

public void onServiceDisconnected(ComponentName name) {

mService = null;

Log.d( "ADDERSERVICECLIENT","onServiceDisconnected" );

}

};

private void initService()

{

conn = new NetServiceConnection();

Intent i = new Intent();

i.setClassName( "framework.network", "framework.network.NetService" );

if (!bindService( i, conn, Context.BIND_AUTO_CREATE))

{

Toast.makeText(this, "bindService fails..", Toast.LENGTH_LONG).show();

}

}

....

mService.sendString((char)0, finalMessage);

The methods defined in INetService.Stub, like sendString, appear never to be called; clearly I'm missing something; any thoughts?

Thanks a lot!

Iva

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值