【问题标题】:bindService 'is undefined' when changing from Activity to Fragment?从 Activity 更改为 Fragment 时,bindService '未定义'?
【发布时间】:2012-12-07 13:02:30
【问题描述】:

我想将我的从扩展 Activity 更改为扩展 Fragment,但看到的错误包括:

bindService -> 文件名未定义方法bindService(Intent, ServiceConnection, int),我的文件名从扩展Activity改为Fragment?

有人遇到过同样的问题吗?我正在使用 v4.support 库进行开发

【问题讨论】:

  • Nikita 的解决方案有效 :) 你应该接受 sebastian 的答案

标签: android android-fragments android-fragmentactivity


【解决方案1】:

试试getActivity().bindService(Intent, ServiceConnection, int)

fragmet 中没有bindService 方法。但是放置在某些活动中的每个片段都可以使用它来绑定服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    相关资源
    最近更新 更多