How to get the intent that stops the service in android

一个人想着一个人 提交于 2020-01-11 09:23:26

问题


I am using stopService() to stop the service . and I want to send Extra data with the intent . how to retrieve this extra data in the service ??


回答1:


AFAIK, this Intent is not delivered to the Service in any fashion.

Instead of stopService(), you can use startService() to pass your extras, and include something in there that causes your service to call stopSelf(). This will have the net effect of calling stopService() and supplying extra data at the same time.




回答2:


I understand this is an old question but, if anyone's looking for an alternative, you can register a BroadcastReceiver in your Service for stopping the service and then send broadcast to this receiver from all over your app. Here, you can get all the information from the intent sent to the receiver. Within the receiver, simply call stopSelf().



来源:https://stackoverflow.com/questions/17948578/how-to-get-the-intent-that-stops-the-service-in-android

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