Activity 可以引用 Service 吗?
我知道 服务可以引用 Activity 。相反的情况成立吗?
我有一项监视我的音频播放/暂停/停止的服务。在我的活动中,我有 3 个用于这些功能的按钮和一个搜索栏。
我想在活动中按下相应的按钮时调用服务中的适当函数。另外,我希望eekBar 将其最大值设置为服务中的音频长度。
因此,我认为我需要引用我的服务才能做到这一点。
我是对的还是什么?
I know that Service can have a reference to Activity. Does the opposite hold ?
I have a service that monitor my Audio play/pause/stop . In my activity, I have 3 buttons for these functions and a seek bar also.
I want to call the appropriate function at the Service when the corresponding button is pressed at the Activty. Also I want the seekBar to set its max to the Audio length at the service.
So, I figured that I need a reference to my service in order to do that.
Am I right or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
服务不应保存对活动的引用,因为这可能会导致内存泄漏。活动可以引用服务,这称为“本地绑定服务”。 " 中详细介绍了这是什么以及如何实现和使用它。 Android 文档中的“绑定服务” 文章。
Services should not hold references to activities, as this may result in memory leaks. An Activity can have a reference to a Service, this is called "Local Bound Services". A detailed explanation of what this is and how to implement and use it described in "Bound Services" article in Android's documentation.