How to get the intent that stops the service in an

2019-02-23 08:05发布

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 ??

2条回答
干净又极端
2楼-- · 2019-02-23 08:42

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

查看更多
The star\"
3楼-- · 2019-02-23 08:48

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.

查看更多
登录 后发表回答