0

I'm building a news reader for Android, where the first Activity will show a list of the latest news, combined with a thumbnail preview image. In order to get the thumbnail I have to run a method, which increase heavily the loading time; so, I was thinking to create a separate thread to run everytime. More specifically I'd like to load the news titles first, and then load the pictures, one by one; while doing all this I don't want the UI to be locked (for instance, if an user touches a news I want the app to load it, even if thare are some thumbnails still loading). My question is: should I use handlers (one thread for each news) or AsyncTask (one asyncTask object for each news) to achieve this?
Thank you for your replies.

user1012480
  • 752
  • 2
  • 11
  • 24

3 Answers3

0

i wit make asynch task for loading the data and then excute a task thats populate the list when the async task is don ore while it is running

0

Handler Vs AsyncTask

I would use an asynctask to download all the "news links" and then have that asynctask call an asynctask to download each thumbnail and update the UI onPostExecute. Then, if the user clicks a link before it is done, you could call cancel on the main Asynctask, which would check for isCancelled() between each thumbnail asynctask and would return if it was cancelled.

Community
  • 1
  • 1
Motomotes
  • 4,111
  • 1
  • 25
  • 24
0

No doubt that AsyncTasks are more simplified and modularized than the thread-handler architechture, but internally they perform the action in same way.
Coming to your problem, I would suggest that load the news first.
Your news pojo/class can be like containing two feilds,
title and imageUrl.

Now display the news list and start another AsyncTask that fetches the images one by one and store them in a Data Str/list.

your adapter should be "notifyDataSetChanged()" every time the image is fetched from server.

This way you are allowing user to see the news first, and the images are loaded without making UI get blocked.

akkilis
  • 1,904
  • 14
  • 21