tags:

views:

303

answers:

2

I'm doing an IPC between a client Activity and a Service using AIDL. ServiceConnection.onServiceConnected() seems to run when binding the Service with bindService(). However after unbindService() is called when releasing the Service, there's no indication ServiceConnection.onServiceDisconnected() is ever run. Can anybody provide any insight as to why this happens?

Found another thread on this issue here: http://stackoverflow.com/questions/971824/when-does-serviceconnection-onservicedisconnected-get-called

Which doesn't quite answer my question. My Service didn't fail on any exception.

Here's my service binding and releasing code:

//bind service
private void initService()
{
    conn = new NetServiceConnection();
    Intent i = new Intent();
    i.setClassName( "framework.network", "framework.network.NetService" );
    bindService( i, conn, Context.BIND_AUTO_CREATE);//This returns TRUE
}

//unbind service
private void releaseService()
{
    unbindService(conn);
    conn = null;
}

class NetServiceConnection implements ServiceConnection
{

    //THIS RUNS FINE
    public void onServiceConnected(ComponentName name, IBinder service) {
         mService = INetService.Stub.asInterface(service);
          Log.d( "ADDERSERVICECLIENT","onServiceConnected" );
    }

    //THIS DOESN'T RUN
    public void onServiceDisconnected(ComponentName name) {
        mService = null;
        Log.d( "ADDERSERVICECLIENT","onServiceDisconnected" );
    }
};

Any help is very much appreciated. Thanks in advance.

A: 
Christopher
A: 

OnServiceDisconnected() is called when a connection to the Service has been lost. This typically happens when the process hosting the service has crashed or been killed.

in a simpler way:::

This is called when the connection with the service has been unexpectedly disconnected -- that is, its process gets crashed.

Hope this solves ur prob.

Ambika