¿Cómo puedo asegurarme de que solo se crea una instancia de servicio?Crear solo una instancia de servicio (Android)
He comprobado que algunas funciones con el registro (WeatherService es la clase que se extiende de servicio):
Log.i(TAG, "Start Id:" + WeatherService.this.hashCode());
Log.i(TAG, "End Id:" + WeatherService.this.hashCode());
Da diferentes códigos hash incluso cuando estoy seguro de que la misma función se ejecuta dos veces (la descarga):
09-12 01:00:55.195: INFO/WeatherService(7222): Start Id:1137653208
09-12 01:00:57.235: INFO/WeatherService(7222): Start Id:1137654296
09-12 01:00:59.035: INFO/WeatherService(7222): Start Id:1138806536
09-12 01:01:39.085: INFO/WeatherService(7222): End Id:1137654296
09-12 01:01:39.265: INFO/WeatherService(7222): Start Id:1137654296
09-12 01:02:22.175: INFO/WeatherService(7222): End Id:1137653208
09-12 01:02:24.815: INFO/WeatherService(7222): End Id:1138806536
09-12 01:02:24.836: INFO/WeatherService(7222): Start Id:1138806536
09-12 01:02:40.275: INFO/WeatherService(7222): End Id:1137654296
Estoy atando un Actividad para el servicio con:
bindService(new Intent(getApplicationContext(), WeatherService.class)
,mServiceConnection, BIND_AUTO_CREATE);
Y el servicio puede ejecutarse durante minutos hasta que se complete, por lo tanto, el servicio puede vincularse/crearse en muchas actividades
También vea esta página, que me siento tiene una explicación útil también: http://stackoverflow.com/questions/2518238/does-startservice-create-a-new-service-instance-or- using-the-existing-one –