Reasons why an IntentService won't start? [clo

2019-05-11 14:20发布

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条回答
老娘就宠你
2楼-- · 2019-05-11 14:53

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.

查看更多
登录 后发表回答