Android Context.bindService 总是返回 false 并且永远不会触发 ServiceConnection 对象 [英] Android Context.bindService always returns false and ServiceConnection object is never triggered
问题描述
我遵循了本地服务示例Google,但我的 Context::bindService(...)
总是返回 false 并且 ServiceConnection::onServiceConnected
也从未被调用.
我知道 Context::bindService()
立即返回,但我的 ServiceConnection
对象从未被触发.
我不知道这些是否适用
- 我的活动在 tabHost 内运行,我想知道这是否会以任何方式影响服务绑定.
- 服务本身可能有问题,但我可以使用相同的
Intent
调用同一个服务的启动服务,并且它按预期工作.
有人有这方面的经验吗?请帮帮我.
谢谢,附言我的目标是 Android 1.6
所以我终于想通了.事实证明,TabSpec 不能绑定到活动><块引用>
使用 getApplicationContext().bindService 而不是只对您的 bindService活动解决了这个问题,因为它使用了更高级别的应用程序上下文.
希望这对某人有所帮助!
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
- My activity is running inside a tabHost and I was wondering if that can affect service binding in any way.
- 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
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!
这篇关于Android Context.bindService 总是返回 false 并且永远不会触发 ServiceConnection 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!