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?
We can stop the services by stopSelf() and stopService(), in some cases android will kill the services due to the low memory problem.
The onStop() and onDestroy() methods get called, and Android destroys the activity. A new activity is created in its place.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
A cached process is one that is not currently needed, so the system is free to kill it as desired when resources like memory are needed elsewhere.
use this line:
this.stopSelf();
to kill itself.
Or from outside use stopService(intent);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With