After I have bound a service by calling:
bindService(new Intent(IBumpAPI.class.getName()), connection, Context.BIND_AUTO_CREATE);
I need for debugging purposes to make the onServiceDisconnected() get called.
I am aware that the Android system calls this when the connection to the service is unexpectedly lost, such as when the service has crashed or has been killed and that this is not called when the client unbinds.
So my question is how to force the onServiceDisconnected() get called whenever I want so I can complete a test?
You need to start you service then bind with Context.BIND_NOT_FOREGROUND flag and then stop it. This will cause onServiceDisconnected to be called. Here is code (assuming that you have TestService service defined) of MainActivity with two buttons which are linked to call doBind and doUnbind methods:
This code provides following logs when you click on buttons:
You might just unbind your service