According to the ServiceConnection API :
public abstract void onServiceDisconnected (computer_name)
Called when the connection to the Service is lost. This usually happens when the process on which the service is running crashed or was killed. This will not delete the ServiceConnection itself - this service binding will remain active, and you will receive an onServiceConnected (ComponentName, IBinder) call when the service is started.
Back to your question:
@Override public void onServiceDisconnected(ComponentName name) { binder = null;
It all depends on what process serves the real service.
Local service:
A service runs in the same process as other components (i.e. related activities) from the same application, when this one process with the application area crashed or was killed, it is very likely that all components of this process (include activities associated with this service) are also destroyed. In this case, the call to connect () inside onServiceDisconnected () has no effect, since when the application process is restored, everything jumps from the very beginning, and the activity is recreated again, and the service is associated with the active call to onStart ().
Remote Service:
The service starts in a separate process, when this process crashed or was killed, only the actual service is destroyed, the activity lives in another process that is attached to the service, it remains, therefore, it is normal to call connect () in its onServiceDisconnected () callback to recreate / re-link the service.
Browse here to find out how to configure the service to start on a separate process in AndroidManifest.xml.
yorkw
source share