Could anyone tell me how to stop intentservice
in Android?
If I use stopservice
to stop an intentservice, it doesn't work.
I have browsed the website, but nobody has given a clear answer to this question.
Could anyone tell me how to stop intentservice
in Android?
If I use stopservice
to stop an intentservice, it doesn't work.
I have browsed the website, but nobody has given a clear answer to this question.
Try calling stopSelf()
from within the service. The documentation says that some processes may take a long time to complete, so your service is most likely waiting for them to stop. You should probably look into that. Once all requests are complete, the service stops itself.
The IntentService
is built to stop itself when the last Intent is handled by onHandleIntent(Intent)
- i.e. you do not need to stop it, it stops it self when it's done.
Belated reply in case someone has the same issue. If you call <yourContext>.stopService(intent)
where intent
is the same intent object you used to start the service then it will work.
An IntentService is designed to stop itself only when all the requests present in the work queue have been handled.As per docs,IntentService class "Stops the service after all of the start requests are handled, so you never have to call stopSelf()"
According to the documentation Android stops the service after all start requests have been handled, so you never have to call stopSelf().
Intent services automatically stop with
stopSelf()
only when all the requests present in the work queue have been handled.