How to get the intention to stop the service in android

I use stopService() to stop the service. and I want to send additional data with the intention. How to get this additional data in the service?

+4
source share
2 answers

AFAIK, this Intent not passed to Service any way.

Instead of stopService() you can use startService() to pass in your extra functions and enable something there, which is why your service calls stopSelf() . This will have the pure effect of calling stopService() and providing additional data at the same time.

+9
source

I understand this is an old question, but if someone is looking for an alternative, you can register BroadcastReceiver with your Service to stop the service and then send broadcasts to this receiver from the entire application. Here you can get all the information from intent sent to the receiver . Inside receiver just call stopSelf() .

0
source

Source: https://habr.com/ru/post/1494299/


All Articles