In my application, I am parsing XML data using SAX Parser. But, I want to put the whole parsing operation in background, i.e., I want to do this using worker thread. Which will be the best solution for this, using handler, AsyncTask or services, as I am having lots of confusion between the three.
Share
A
Handlerdoesn’t do any work; it’s a means for passing off processing between a background thread and the UI thread. AnAsyncTaskis the way to go here: it has a built-inHandlerso you can do something back on the UI thread when you’re done, or even publish updates as work progresses. It’s just like using a plain workerThread, but with the convenience of theHandlerbuilt in. Of course, you can use a workerThreadandHandleryourself if the way aHandlerworks isn’t a good match to your needs.A
Servicesounds like overkill for this; it’s a way to make processing available to other activities. It also doesn’t get around the problem: theServiceis invoked on the UI thread and it needs to fire up a separate thread to avoid blocking the UI.