2

I'm using multiple lists embedded one inside another. This obviously slows down the App, thus I thought of using multi-threading. Treating separate lists as threads, and then the data loaded inside them as separate threads to make it faster.

Is this a better way to do it? Can I've certain examples based on it? Or even links?

Hick
  • 35,524
  • 46
  • 151
  • 243

3 Answers3

7
  • The Handler is associated with the application’s main thread. it handles and schedules messages and runnables sent from background threads to the app main thread.

  • AsyncTask provides a simple method to handle background threads in order to update the UI without blocking it by time consuming operations.

It is better to use an async task to load a listview so you dont block the main UI

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
0

Handler and AsyncTasks are way to implement multithreading with UI/Event Thread.

Handler can be created from any thread and it runs on the thread which created it.

It handles and schedules messages and runnables sent from background to the thread which created it . We should consider using handler it we want to post delayed messages or send messages to the MessageQueue in a specific order.

AsyncTask is always Triggered or created from main thread.

Its methods onPreExecute(),onPostExecute(),onProgressUpdate() runs on main thread(or UI thread) and doInBackground() runs on worker thread(or background thread).AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread .

We should consider using AsyncTask if you want to exchange parameters (thus updating UI) between the app main thread and background thread in an easy convinient way.

Android Developer
  • 9,157
  • 18
  • 82
  • 139
0

Your question title does not match the question body, you'll get better responses if you change them to relate better.

See the following question for an explaination of the differences: How to know when to use an async task or Handler

That said, in your case, you want to parralelize the population of the listboxes as opposed to the handling of messages, so AsyncTask makes most sense.

Community
  • 1
  • 1
stevenrcfox
  • 1,547
  • 1
  • 14
  • 37