I followed this answer from stackoverflow:
Lazy load of images in ListView
and the same from Github:
https://github.com/thest1/LazyList
where in the last line of Basic Usage
, it says:
Please create only one instance of ImageLoader and reuse it all around your application. This way image caching will be much more efficient.
How can i do this?
I have lot of ListView(10-15) and so far i am using this way in the Adapter class, as given in the Example:
public ImageLoader imageLoader;
public LazyAdapter(Activity a, String[] d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
I tried doing this:
Create a static variable in the first class, and use it everywhere else:
Class first{
public static ImageLoader imageLoader;
}
Class LazyAdapter{
first.imageLoader = new ImageLoader(activity.getApplicationContext());
//use it
}
But isn't this same as creating different instances? I mean i will be creating a new instance in every Adapter, of course the previous instance is gone(not more reference).
So, is this the right way to use?
EDIT:
Also this is written in the code:
public File getFile(String url){
//I identify images by hashcode. Not a perfect solution, good for the demo.
String filename=String.valueOf(url.hashCode());
//Another possible solution (thanks to grantland)
//String filename = URLEncoder.encode(url);
File f = new File(cacheDir, filename);
return f;
}
So, should i use String filename = URLEncoder.encode(url);
??
and
//use 25% of available heap size
by heap size it mean RAM? or the MAX RAM that can be allocated to an Applcation (I read somewhere it is 19mb).
Because according to the Device(Samsung Galaxy GT-S5830) Specifications:
Internal- 158 MB storage, 278 MB RAM
But in log i get
01-23 06:23:45.679: I/MemoryCache(1712): MemoryCache will use up to 16.0MB
which is 25% as set in the code.
If it is like 25% of available memory. Then in Settings -> Applications -> Manage Applications:
At the bottom, it says 159MB used 21MB free.
ThankYou