我有一个后台服务,我想在其中显示允许用户停止它的通知。
在 android SDK 文档中,它说 Activity 用于正常启动 Activity 。所以我想知道我是否需要创建一个 Activity 来停止服务,或者我可以在用户选择通知时直接停止服务,
那么打算如何回调服务来停止它..
谢谢,
最佳答案
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,
您不能通过通知
直接停止服务。您可以启动服务,使用具有操作字符串或额外内容的Intent
或服务在onStartCommand()
中看到并触发它的内容调用 stopSelf()
。
关于android - 从通知中停止后台服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11145679/