Android Context.bindService 总是返回 false 并且 ServiceConnection 对象永远不会被触发

发布于 2024-10-09 03:32:34 字数 526 浏览 0 评论 0原文

我遵循了 Google 提供的本地服务示例,但是我的Context::bindService(...) 始终返回 false,并且 ServiceConnection::onServiceConnected 也从未被调用。

我知道 Context::bindService() 会立即返回,但我的 ServiceConnection 对象永远不会被触发。

我不知道这些是否适用

  1. 我的活动正在 tabHost 内运行,我想知道这是否会以任何方式影响服务绑定。
  2. 服务本身可能有问题,但我可以使用相同的 Intent 调用启动服务来启动服务,并且它按预期工作。

有人有这方面的经验吗?请帮帮我。

谢谢, PS我的目标是Android 1.6

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2024-10-16 03:32:34

所以我终于想通了。事实证明,TabSpec 无法绑定到 Activity

在您的应用程序上使用 getApplicationContext().bindService 而不是仅使用 bindService
Activity 解决了这个问题,因为它使用了更高级别的应用程序上下文。

希望这对某人有帮助!

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!

离不开的别离 2024-10-16 03:32:34

我现在这已经很旧了,但我遇到了一个稍微不同的问题。我重构了我的项目的包。因此文件的名称发生了变化,但 Eclipse 没有更新清单文件。因此,我手动修复了清单文件并更改了包的名称。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文