如何通知 Activity 有关 Service 的进度

发布于 2024-12-10 10:55:22 字数 230 浏览 3 评论 0原文

我正在编写一个带有 3 个 Activity() 的 Android 应用程序:A、B 和 C;和一个服务:S。用户可以使用活动A启动该服务。该服务运行很长时间,分7个步骤。每个步骤需要几秒钟(或几分钟)。一旦步骤完成,我希望服务通知 Activity() B 和 C 其进度(如果它们可见)。也就是说,我想通知与启动服务不同的活动。如果 Activity 不可见,则无需显示它。

我该怎么做?最干净和/或最简单的解决方案是什么?

I'm writing an Android app with 3 Activity()s: A, B and C; and one Service: S. The user can start the service using activity A. The service runs for a long time, in 7 steps. Each step takes a few seconds (or minutes). Once a step has completed, I want the service to notify Activity()s B and C about its progress if they are visible. That is, I want to notify an Activity different from which has started the Service. There is no need the show an Activity if it's not visible.

How do I do that? What is the cleanest and/or simplest solution?

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

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

发布评论

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

评论(1

以为你会在 2024-12-17 10:55:22

在运行时注册接收器并监听/发布事件。 这个答案提供了一个示例

Register a receiver at runtime and listen/publish the events. This answer provides an example

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