停止从通知后台服务 [英] Stopping a background service from notification
问题描述
予具有其中我要显示一个通知允许用户来阻止它后台服务
在Android SDK文档,它说的活动是用于正常启动的活动。所以我想知道如果我需要创建活动停止服务,也可以我就直接停在用户选择通知的服务,
那么会怎么打算回叫服务停止吧..
谢谢
所以,我想知道如果我需要创建活动停止服务,也可以我就直接停在用户选择通知的服务,
您不能直接阻止来自通知
服务。你可以的启动的服务,使用意图
,有一个操作字符串或额外什么的服务看到在 onStartCommand ()
键,触发它来调用 stopSelf()
。
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 launch an 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,
So how would the intend call back the service to stop it..
Thanks,
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()
.
这篇关于停止从通知后台服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!