Android 服务将一个活动的多个实例放入历史记录中

发布于 2024-10-09 09:52:56 字数 253 浏览 0 评论 0原文

我正在制作一个音乐播放器。当您按下播放时,它会将通知加载到“正在进行”部分。当您转到系统中的其他任何地方时,我希望音乐继续播放。这一切都很好。

问题是,当我从通知重新启动我的活动时,它每次都会向历史堆栈添加一个任务,所以如果我回击,我必须从我按下播放的位置看到活动 B 的实例,并且每次我单击通知返回到活动 B。

我希望从通知(通过服务)启动的活动 B 的实例成为历史记录中该活动的唯一副本。我一直在清单中尝试各种意图标志和活动属性,但我还没有找到正确的组合。

I'm making a music player. When you press play, it loads a notification into the OnGoing section. When you go anywhere else in the system, I want the music to keep playing. All of this is fine.

The problem is that when I relaunch my activity from the Notification, it adds a task to the history stack each time, so if I hit back, I have to see the instance of Activity B from where I pressed play, and from every time I clicked on the notification to go back to Activity B.

I want the instance of Activity B that I launch from the notification (via the service) to be the only copy of that Activity in the history. I've been playing around with various Intent flags and Activity attributes in the manifest, but I haven't found the proper combination.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2024-10-16 09:52:56

使用:(

setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

调用您与 NotificationPendingIntent 一起使用的 Intent

Use:

setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

(called on your Intent you are using with your PendingIntent for your Notification)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文