Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the intent that stops the service in android

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

like image 799
Adham Avatar asked Jul 30 '13 13:07

Adham


People also ask

Can we stop intent Service?

Work is submitted to the queue by creating an Intent and then passing that Intent to the StartService method. It is not possible to stop or interrupt the OnHandleIntent method IntentService while it is working.

How can we stop the service in Android?

Stopping a service. You stop a service via the stopService() method. No matter how frequently you called the startService(intent) method, one call to the stopService() method stops the service. A service can terminate itself by calling the stopSelf() method.

How do I stop a service from activity?

To start the service, call startService(intent) and to stop the service, call stopService(intent) .

Does intent service run in background?

IntentService runs outside the application in a background process, so the process would run even if your application is closed.


1 Answers

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.

like image 183
CommonsWare Avatar answered Oct 19 '22 19:10

CommonsWare