Reputation: 2205
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
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
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:
Upvotes: 1
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