How to stop intentservice in android?

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

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.

回答1:

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.



回答2:

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.



回答3:

According to the documentation Android stops the service after all start requests have been handled, so you never have to call stopSelf().



回答4:

Belated reply in case someone has the same issue. If you call .stopService(intent) where intent is the same intent object you used to start the service then it will work.



回答5:

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()"



回答6:

Intent services automatically stop with

stopSelf()

only when all the requests present in the work queue have been handled.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!