服务可以在 onBind 期间获取对 Activity 的引用吗?

发布于 2024-10-05 11:18:18 字数 225 浏览 0 评论 0原文

我有一项服务,主要管理用于播放播客MediaPlayer 实例。一旦活动绑定到服务,它就可以执行播放、暂停、停止等操作。我使用服务是因为我希望播客即使在活动被销毁后也能继续播放。

我希望该服务能够在出现错误或正常状态更新时将消息发送回活动。该服务是否可以获取对尝试绑定到它的活动的引用?看起来似乎没有意图使其可用。

I have a service that basically manages a MediaPlayer instance for playing podcasts. Once an activity binds to the service it can do things like play, pause, stop, etc. I used a service because I want the podcast to continue playing even after the activity is destroyed.

I'd like the service to be able to send messages back to the activity in case of an error or for normal status updates. Is it possible for the service to get a reference to the activity that's trying to bind to it? Doesn't look like the intent makes this available.

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

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

发布评论

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

评论(1

鸩远一方 2024-10-12 11:18:18

SDK 示例 API 演示应用程序有一个向活动发回消息的服务示例

The SDK samples API Demos app has an example of a service that messages back to an activity

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