I have several services that are similar and implement a MyAbstractService
abstract class.
public Service1 extends MyAbstractService {
// ...
}
public Service2 extends MyAbstractService {
// ...
}
public abstract MyAbstractService extends Service {
// ...
}
Usually an activity binds to only one service.
But I have an activity that needs to bind to all of them. I am wondering whether I can use one ServiceConnection
public void onCreate() {
bindService(intentService1, mConnection);
bindService(intentService2, mConnection);
}
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MyAbstractService.LocalBinder binder = (MyAbstractService.LocalBinder) service;
MyAbstractService svc = binder.getService();
# The activity keeps all connected services in a HashMap
mServices.put(name, svc);
}
};
Can I reuse the same mConnection
or do I need to create one ServiceConnection
per connected Service
?