Stopping a background service from notification

后端 未结 3 1547
南方客
南方客 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:08

    You can't start an Acitivty from a Service just like that. What you can do is create a callback to an Activity in the Service and let the callback start new activities. But having a notification means you don't have to go through the Service. When the notification is clicked, you can start an activity that's specified in the Intent you supply to the notification. It's really very simple.

    Do read the reference docs on notifications for examples.

提交回复
热议问题