How to create a service with one thread in it?
Create a service with one thread in OnCreate().
Use Intent Service
Both option1 and 2 are right
Default with every service will one worker thread, so no need to create it.
If you want a service with one thread, then go for IntentService, or a normal service with a thread in onCreate().
onCreate will be called only once, so if you create a thread there, then it will become a service with single thread.
But make sure that from onStartCommand you are queuing up the requests to that thread using some handlers.
Even if you use IntentService also, that will also create only one thread in that service. Using IntentService is a good option to go for a service with single thread.
Back To Top