You still have to spawn a Thread
into background for IO or use a IntentService
which does that for you.
See the Service as a process running on the UI Thread, although it has no UI itself.
Domanda
I added some network socket code in the onStartCommand()
method of my implementation of Service
class. But I got NetworkOnMainThread
exception. Some folks suggested that a Service runs on UI thread, which makes sense to me. However the doc says Service is intended for long running operations, this is confusing since how could a long-running service not blocking UI if it runs on UI thread?
Soluzione
You still have to spawn a Thread
into background for IO or use a IntentService
which does that for you.
See the Service as a process running on the UI Thread, although it has no UI itself.