简体   繁体   中英

How to stop intentservice in android?

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.

IntentService是为了在onHandleIntent(Intent)处理最后一个Intent时自行停止 - 即你不需要停止它,它会在完成后自动停止它。

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.

IntentService旨在仅在处理了工作队列中存在的所有请求时停止自身。根据文档,IntentService类在处理完所有启动请求后停止服务,因此您永远不必调用stopSelf()”

根据文档, Android在处理完所有启动请求后停止服务,因此您永远不必调用stopSelf()。

Intent services automatically stop with

stopSelf()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM