【问题标题】:OnServiceConnected is not called未调用 OnServiceConnected
【发布时间】:2016-04-11 11:23:24
【问题描述】:

这是我的服务连接:

   private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
        Log.i("","onServiceConnected TRUE");
        locationService = ((LocationService.ServiceBinder)service).getService();
    }

    public void onServiceDisconnected(ComponentName className) {
        Log.i("","onServiceConnected TRUE DISCONNECT");
        locationService = null;
    }
};

从来没有输入过。 我这样称呼它:

  void doBindService() {
    bindService(new Intent(this, LocationService.class), mConnection, Context.BIND_AUTO_CREATE);
}

来自我的 ApplicationClass onCreate:

  Intent i= new Intent(PSLocationCenter.this, LocationService.class);
    startService(i);
    doBindService();

我在清单中有这个:

   <service android:name=".services.LocationService" android:enabled="true"/>

我是否试图错误地绑定它?为什么不调用。

【问题讨论】:

  • 没有它会启动吗?
  • 去掉startService还是不行

标签: android service bind serviceconnection bindservice


【解决方案1】:

我知道这已经晚了,但也许它会对某人有所帮助。 这个答案很有意义:using getApplicatinContext 我必须承认它还没有为我工作,我还在寻找,但你似乎遇到了和他一样的问题。

【讨论】:

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