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

2

17

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?

Habited answered 20/12, 2012 at 9:27 Comment(2)
stopSelf is the method to stop a service from itselfStultz
we have stopservice .. and stopself .. options.. you should try with one of those..Callboy
P
36

use this line:

this.stopSelf();

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

Pled answered 20/12, 2012 at 9:29 Comment(0)
D
5

you can try as to stop your AudioService service from broadcast receiver :

Intent intent = new Intent();
intent.setClass(context, AudioService.class); 
context.stopService(intent);

where context is first param which you received in on Receive of broadcast receiver

Duffer answered 20/12, 2012 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.