如何通知 Activity 有关 Service 的进度
我正在编写一个带有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在运行时注册接收器并监听/发布事件。 这个答案提供了一个示例
Register a receiver at runtime and listen/publish the events. This answer provides an example