服务可以在 onBind 期间获取对 Activity 的引用吗?
我有一项服务,主要管理用于播放播客的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SDK 示例 API 演示应用程序有一个向活动发回消息的服务示例
The SDK samples API Demos app has an example of a service that messages back to an activity