1

Good day all, i have a load of images i want to display from an sdcard to a gridview. I have followed the tutorial to do this in the is link:

http://mihaifonoage.blogspot.com/2009/11/displaying-images-from-sd-card-in.html

everything works great apart the fact that when the images become a lot, it becomes really slow to populate it and scrolling is also very slow. i have tried editing the code to use the ViewHolder method but still no luck.

now, i also have used populated the images in a custom ListView without using the AsyncTask and it appears to process it faster. yeah common sense would be to just use the faster method but want to clarify somethings first. so i am asking:

  1. is it that AsyncTask can be really slow in some cases and not ideal or thus the fact that am using a Gridview or Listview have something to do with it? any reason why? am asking this cause AsyncTask always seem to get very good favourism.

  2. Any Other way, solutions or tips that i can make this process faster?..

Note: i would have posted my code, but its the same things as the link only that i don't use the getThumbnails() in the MediaStore query. Thanks in advance.

here is part what i get for the logcat output when its loading the images:

10-07 19:42:54.072: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2886K/5511K, external 1574K/14018K, paused 28ms

10-07 19:42:54.092: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 1574K/14018K, paused 25ms

10-07 19:42:54.122: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 1574K/14018K, paused 25ms

10-07 19:42:54.142: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 1574K/14018K, paused 24ms

10-07 19:42:54.172: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 1574K/14018K, paused 25ms

10-07 19:42:54.202: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 1574K/14018K, paused 25ms

10-07 19:42:54.232: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 28ms

10-07 19:42:54.252: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 24ms

10-07 19:42:54.282: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 24ms

10-07 19:42:54.302: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 25ms

10-07 19:42:54.332: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 25ms

10-07 19:42:54.362: DEBUG/dalvikvm(20291): GC_EXPLICIT freed <1K, 48% free 2918K/5511K, external 14018K/14018K, paused 25ms
irobotxx
  • 5,963
  • 11
  • 62
  • 91
  • can you post the logcat messages that are produced when the device slows down. I suspect you are running out of memory. – slayton Oct 07 '11 at 18:05
  • @slayton i have added what the logcat message looks like. Strange, but i don't get any errors or warning message. i don't know if i should use the BitmapFactory InSampleSize options to reduce the size of the image, but that won't that reduce the image quality as well? – irobotxx Oct 07 '11 at 18:50
  • If your images are a higher resolution than the number of pixels they get on the screen there is no reason not to downsample them with inSampleSize – slayton Oct 07 '11 at 19:06

2 Answers2

0

The right way to speed this up would be to use a image cache. Google has a guide for an easy implementation right here:

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
tobalr
  • 1,597
  • 15
  • 14
0

It is slow because in fact you are still using one single thread (i.e. one AsyncTask.execute() call) download all images in sequence (i.e. loop all image download in your doInBackground() implementation). Yes, this is the way that google suggested how to use AsyncTask.

By calling several AsyncTask.execute() will probably speed you up, this gives you several thread running simultaneously and managed by underlying thread pool (before API level 11, this thread pool is non accessible). of cause, you need somehow split your download task into several piece and feed each piece into each AsyncTask.execute():

for (DownloadTask task : tasks) {
  new AsyncTask.execute();
}

Check out here for more information.

Community
  • 1
  • 1
yorkw
  • 40,926
  • 10
  • 117
  • 130