I am a little bit confused regarding the usage of IntentService.
I am pretty sure I read somwhere in the documentation that onStartCommand() is called by the system only once, if you issue twice a startService(), the second call will not result in onStartCommand() being called.
I might be wrong here, because I have been looking for this piece of documentation and I cannot seem to find it.
This contradicts the previous concept that says you can queue many intents in IntentService through onStartCommand().
So I need help here, how do I queue multiple intents on an IntentService?
I see only two options:
Just call everytime startService() with different intents
Call directly onStart() or onStartCommand() (bypassing startService())
You send the Intent
with Context.startService()
and the Intent is picked up by your service in onHandleIntent()
.
The first time you call startService()
will result in the service's onStartCommand()
being invoked. Think of it as a constructor. Subsequent calls to startService()
do not need to start the service again, since it's already running; they will just result in more calls to the service's onHandleIntent()
.