Googling around, I have seen this problem posted many times, some of the posts on this forum over that last few years. I have never seen anyone get a straight answer.
I have a foreground service that tries to stop itself after running for 2 hours by doing a this.StopSelf(). I've tried it when it's bound and when it's unbound. On the AVD and on a device.
It simply does not work. Is this a bug in Android? (running 2.3.3).
How can a service stop itself?
If you use a foreground service, you should call:
stopForeground(true);
Just like you start it with startForeground
.
stopSelf
is meant to be used for normal services. a foreground service is special... :)
By the way, in case your app should work on older devices, you should check the compatibility code offered here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With