Reasons why an IntentService won't start? [closed]

早过忘川 提交于 2019-12-07 11:58:57

问题


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.)

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.

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?


回答1:


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

  • 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)

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.



来源:https://stackoverflow.com/questions/12958993/reasons-why-an-intentservice-wont-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!