Can I call stopSelf() in Service.onStartCommand?

♀尐吖头ヾ 提交于 2019-11-29 04:21:42

问题


There are some conditions where my service could be attempted to be started when it should not be. In cases like this is it bad form to call stopSelf() while inside a onStartCommand() method? If so what is the best way to handle such a situation? Any resources will be greatly appreciated.


回答1:


is it bad form to call stopSelf() while inside a onStartCommand() method?

Off the top of my head, I can't think of why that would be a problem.

stopSelf(), like a lot of stuff in Android, has no immediate effect. It puts a message on the message queue processed by the main application thread. The actual work of stopping the service will not even begin until sometime after onStartCommand() has returned.



来源:https://stackoverflow.com/questions/8279199/can-i-call-stopself-in-service-onstartcommand

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