Stopping a background service from notification

后端 未结 3 1537
南方客
南方客 2021-01-12 18:38

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

3条回答
  •  独厮守ぢ
    2021-01-12 19:18

    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().

提交回复
热议问题