Чтобы остановить сервис при остановке приложения, нам нужно позвонить unbindService()
в onDestroy()
.
Edit:
В вашей ссылке есть код для этого
@Override
protected void onDestroy() {
super.onDestroy();
try {
api.removeListener(collectorListener);
unbindService(serviceConnection);
} catch (Throwable t) {
// catch any issues, typical for destroy routines
// even if we failed to destroy something, we need to continue destroying
Log.w(TAG, "Failed to unbind from the service", t);
}
Log.i(TAG, "Activity destroyed");
}