问题
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