为什么IntentService无法启动? [英] Reasons why an IntentService won't start?

查看:404
本文介绍了为什么IntentService无法启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个行为异常的Android IntentService.我通过调用startService(intent)向它发送一个意图.

I have an Android IntentService that is behaving strangely. I am sending it an intent via a call to startService(intent).

(很抱歉,我不在办公桌旁,无法粘贴任何实际代码.)

(I apologize, I'm away from my desk and can't paste any actual code.)

当我拨打上述电话时​​,没有任何反应.在Intent Service中既不调用构造函数也不在onHandleIntent方法上.没有编译器警告或错误,我在控制台或日志中看不到任何有趣的东西.

When I make the above call nothing happens. Neither the constructor nor the onHandleIntent methods are called in the Intent Service. There are no compiler warnings or errors and I see nothing of interest in the Console or Log.

当我继续调查这个问题时,我只是想知道是否有一个简短的可能原因清单,说明IntentService无法以这种方式启动而没有明显的理由.清单文件中可能有问题吗?

As I continue to investigate this, I was just wondering if there is a short list of likely reasons why an IntentService would not start like this with no obvious evidence of why. Is the problem likely in the manifest file?

推荐答案

我怀疑您需要仔细研究LogCat.这里的常见问题包括:

I suspect that you need to take a closer look at LogCat. Common problems here include:

  • 未能在清单中列出服务
  • 无法在服务上创建公共零参数构造函数(IntentService的默认构造函数带有一个参数,您需要添加自己的构造函数)
  • 其他语法问题(例如,服务声明为abstract)
  • failed to list the service in the manifest
  • failed to create a public zero-argument constructor on the service (the default constructor for IntentService takes one argument, and you need to add your own constructor)
  • other syntactical problems (e.g., service is declared abstract)

但是,所有这些都会在LogCat中产生消息.我无法想到startService()在LogCat中没有消息的情况下不会调用您的代码的情况.

However, all of those will result in messages in LogCat. I can think of no scenario under which startService() would not invoke your code without a message in LogCat.

这篇关于为什么IntentService无法启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆