活动可以参考服务吗?

iTu*_*rki 3 android android-service android-activity

我知道Service可以引用Activity.相反吗?

我有一项服务可以监听我的音频播放/暂停/停止.在我的活动中,我有3个用于这些功能的按钮和一个搜索栏.

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. 所以,我认为我需要一个对我的服务的引用才能做到这一点.

我是对的还是什么?

ina*_*ruk 6

服务不应该包含对活动的引用,因为这可能会导致内存泄漏.活动可以引用服务,这称为"本地绑定服务".详细解释了这是什么以及如何实现和使用它在Android文档中的"绑定服务"一文中描述.