停止从通知后台服务

编程入门 行业动态 更新时间:2024-10-26 06:29:25
本文介绍了停止从通知后台服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

停止从通知后台服务

本文发布于:2023-11-27 10:06:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!