Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
710 views
in Technique[技术] by (71.8m points)

java - Android Context.bindService always returns false and ServiceConnection object is never triggered

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...