Hello,
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 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
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en