Android, unbind service and onServiceDisconnected problem

onServiceDisconnected is only called in extreme situations (crashed / killed).

which is very unlikely to happen for a local service since all your application components normally run in the same process... meaning, unless you intentionnaly unbind or destroy the service, it should remain connected, or die with the component using it.


I used Context.BIND_AUTO_CREATE in bindService. I have fetch same issue after apply its working perfect for me.

bindService(new Intent(this,XMPPService.class),mConnection, Context.BIND_AUTO_CREATE);

Android developer documentation says...

public abstract void onServiceDisconnected (ComponentName name)

Called when a connection to the Service has been lost. This typically happens when the process hosting the service has crashed or been killed. This does not remove the ServiceConnection itself -- this binding to the service will remain active, and you will receive a call to onServiceConnected(ComponentName, IBinder) when the Service is next running.

For more: https://developer.android.com/reference/android/content/ServiceConnection#onServiceDisconnected(android.content.ComponentName)