停止从通知后台服务 [英] Stopping a background service from notification

查看:144
本文介绍了停止从通知后台服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

予具有其中我要显示一个通知允许用户来阻止它后台服务

在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆