35

I have followed the Local Service example provided by Google, but my Context::bindService(...) always returns false and there is ServiceConnection::onServiceConnected is also never called.

I understand that Context::bindService() returns immediately, but my ServiceConnection object is never triggered.

I don't know if these apply

  1. My activity is running inside a tabHost and I was wondering if that can affect service binding in any way.
  2. The Service itself may have a problem, but I can call start service to the same service with the same Intent and it works as expected.

Does anyone have experience with this? Please help me out.

Thanks, P.S. I am targeting Android 1.6

codinguser
  • 5,562
  • 2
  • 33
  • 40
  • Use `adb logcat`, DDMS, or the DDMS perspective in Eclipse and look for *warnings* at the point in time of your binding. A failed binding usually results in a warning. – CommonsWare May 26 '10 at 18:30

2 Answers2

60

So I finally figured it out. It turns out that TabSpec cannot bind to activities

Using getApplicationContext().bindService instead of just bindService on your activity solves the problem as it is using the higher level application context.

Hope this helps someone!

codinguser
  • 5,562
  • 2
  • 33
  • 40
3

I now this is old, but I had a slightly different problem. I refactored the package of my project. So the name changed of the files, but Eclipse did not update the manifest file. So, I manually fixed the manifest file and changed the name of the package there as well.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
  • thank you! argh, forgetting to update that manifest can drive a man insane :( I wish there was an error in the log indicating this... – verboze Aug 25 '15 at 04:05