如果由于某些意外情况而与绑定服务断开连接,在我调用之后,我应该在 onServiceDisconnected 中手动重新连接还是尝试自动重新连接?
public class MyServiceConnection extends Activity implements ServiceConnection {
MyBinder binder;
@Override
protected void onStart() {
super.onStart();
connect();
}
private void connect() {
bindService(new Intent(this, MyService.class),
this, Service.BIND_AUTO_CREATE);
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
binder = (MyBinder) service;
}
@Override
public void onServiceDisconnected(ComponentName name) {
binder = null;
//should i reconnect here ?
connect();
}
}