gpt4 book ai didi

android - 停止通过 Notification Intent 传递的服务

转载 作者:行者123 更新时间:2023-11-29 22:10:11 24 4
gpt4 key购买 nike

在我的应用程序中,我在任务栏中有一个通知,单击它会启动我的程序的新 Activity View 。但是,当我尝试使用停止按钮从此 View 中停止我的服务时,没有任何反应。我假设当我按下通知按钮时,它不会使我的 Activity 与服务保持联系。

当我的应用首次打开时,该服务是通过使用以下 Intent 启动的:

Intent svc = new Intent(this, StreamService.class);
startService(svc);

然后在服务中:

//Intent passed when notification is selected.
Intent notificationIntent = new Intent(this, HomeActivity.class);

知道如何链接回我正在运行的服务吗?或者在选择通知时将原始 Activity/ View 带回前台?

最佳答案

您可以附加到通知的 Intent 应该具有服务 Intent 和特定操作。在您的服务的 onStart 方法中,您可以检查它是一个关闭操作,然后您可以调用 stopSelf()。

关于android - 停止通过 Notification Intent 传递的服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com