I have a background service in which I want to show a notification which allows the user to stop it.
In the android SDK docs it says an activity is used to normally
So I am wondering if I need to create an activity to stop the service or can I directly stop the service when user selects the notification,
You cannot directly stop the service from a Notification
. You can start the service, using an Intent
that has an action string or extra or something that the service sees in onStartCommand()
and triggers it to call stopSelf()
.