I have a foreground service in which I register for location updates, and intent filter for the battery intent Intent.ACTION_BATTERY_CHANGED
, and a LocalBroadcast
. All of these I remove in the onDestroy
of my service as once this service is dead.
I also have changed the return integer in the onStartCommand
from START_STICKY
to START_NOT_STICKY
but this has no effect.
I log when this service is started and destroyed as well as my main activity and it seems that this service just starts on its own without any activities.
The issue is it's a foreground service so a notification accompanies it. This means that when it's started up again randomly, the user sees the notification and I don't want the service to be running on its own accord.
So to recap.
- It is a bound, foreground service.
- I return START_NOT_STICKY
in onStartCommand
- When I no longer need it and close the app, I unbind from it, call stopService and the service's onDestroy is called which is where we unregister all of the receivers.
- The service is randomly started after this.