AMM
AMM

Reputation: 2205

Android ListView with lots of same drawables performance

I'm developing an Android app with a list view that contains lots of drawables. Most of them are the same so I'm trying to use a HashMap that returns the same allocated bitmap when it's needed but still there are lots of allocations and GC actions so that the list gets stuck from time to time when scrolling.

What can I do to optimize the performance in such case?

Caching method - loadImage Using google code

mImageWorker.loadImage(pic_url, holder.pic);
holder.*some bitmap*.setImageBitmap(Utility.getBitmap(context, id); //can be one of 5 bitmaps do I use caching with a hashMap

Upvotes: 0

Views: 2274

Answers (3)

kalandar
kalandar

Reputation: 833

see this example this will helps you....

don't put so much process under the getView() method . this will lack the listview scroll performance if you want to do image crapping or drawable to bitmap conversition or anything .. just do all process before loading adapter.. and just assign values for each row in getView()...

Upvotes: 2

K_Anas
K_Anas

Reputation: 31466

Try to use lazy loading technique using caching, you can find many tutorial on the web:

You have to see this SO thread

Also see this:

Multithreading For Performance, a tutorial by Gilles Debunne.

This is from the Android Developers Blog. The suggested code uses:

  1. AsyncTasks.
  2. A hard, limited size, FIFO cache.
  3. A soft, easily garbage collected cache.
  4. A placeholder Drawable while you download.

Upvotes: 1

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

If you want to optimize the code, try lazy loading concept for loading images in list. Please refer: Lazy Load images on Listview in android(Beginner Level)?

Upvotes: 1

Related Questions