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())
1) Is it possible to have multiple intentService threads at the same time or not? No, each IntentService only has one HandlerThread that it uses to execute requests in the order that "startService" is called.
This class was deprecated in API level 30. IntentService is subject to all the background execution limits imposed with Android 8.0 (API level 26). Consider using WorkManager or JobIntentService , which uses jobs instead of services when running on Android 8.0 or higher.
Android App Development for Beginners Intent Service is going to do back ground operation asynchronously. When user call startService() from activity , it doesn't create instance for each request. It going to stop service after done some action in service class or else we need to stop service using stopSelf().
The Service will only run in one instance.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With