alternative to finish() method for Service class? To kill it dead

Kevik picture Kevik · Dec 20, 2012 · Viewed 13.4k times · Source

I have used the method finish() before in several activities without problems.

however when I tried to call it inside of the broadcast receiver I get the error message from the compiler that "the method finish() is undefined for the type AudioService"

AudioService is the name of my Service class in my Android app.

If there is no finish() method in a Service than what can I call to kill this Service dead?

Answer

Lazy Ninja picture Lazy Ninja · Dec 20, 2012

use this line:

this.stopSelf();

to kill itself.
Or from outside use stopService(intent);