I have written an library connecting to a remote service that calls
return context.bindService(bindIntent,
serviceConnectionSmartCard, Context.BIND_AUTO_CREATE);
with context being the ApplicationContext and serviceConnectionSmartCard being my custom ServiceConnection
public void onServiceConnected(ComponentName className, IBinder service) {
synchronized (this) {
if (waitForConnection) {
waitForConnection = false;
} else {
return;
}
}
if(service == null) {
Log.w(TAG, "Binding to Service failed.");
smartCardReaderService.onConnected(null);
} else {
if (D) Log.d(TAG, "Attached to Server.");
IConnectionService connectionService = IConnectionService.Stub.asInterface(service);
smartCardReaderService.onConnected(connectionService);
}
}
And on Service side I have the following in onBind():
public IBinder onBind(Intent intent) {
if (D) Log.d(TAG, "onBind");
android.os.Debug.waitForDebugger();
return iConnectionService.asBinder();
}
with iConnectionService being an implementation of my AIDL file.
Now my problem: It works as long as I debug the Service (set Breakpoint on the return Statement)
however it doesn’t work when I debug the Activity instead. The ServiceConnection never returns.
BTW: I call
startActivityForResult(...);
calling a remote Activity in Activity.onCreate. Could this be an issue here?
I simply don’t know how to debug such strange behaviour…
Thanks in advance.
The solution was quite simple. Just uncommented
as it will silently wait for the debugger to attach even if not started by my debug application – which is never going to happen.