【问题标题】:Can the Activity have a reference to the Service?Activity 可以引用 Service 吗?
【发布时间】:2011-07-24 13:10:10
【问题描述】:

我知道Service can have a reference to 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. 所以,我认为我需要引用我的服务才能做到这一点。

我是对的还是什么?

【问题讨论】:

    标签: android android-activity android-service


    【解决方案1】:

    服务不应持有对活动的引用,因为这可能会导致内存泄漏。一个活动可以引用一个服务,这被称为“本地绑定服务”。 Android 文档中的"Bound Services" 文章中描述了这是什么以及如何实现和使用它的详细说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多