android - LazyLoading of images in a ListView -



android - LazyLoading of images in a ListView -

i followed reply stackoverflow:

how do lazy load of images in listview

and same github:

https://github.com/thest1/lazylist

where in lastly line of basic usage, says:

please create 1 instance of imageloader , reuse around application. way image caching much more efficient.

how can this?

i have lot of listview(10-15) , far using way in adapter class, given in 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 static variable in first class, , utilize everywhere else:

class first{ public static imageloader imageloader; } class lazyadapter{ first.imageloader = new imageloader(activity.getapplicationcontext()); //use }

but isn't same creating different instances? mean creating new instance in every adapter, of course of study previous instance gone(not more reference).

so, right way use?

edit:

also written in code:

public file getfile(string url){ //i identify images hashcode. not perfect solution, demo. string filename=string.valueof(url.hashcode()); //another possible solution (thanks grantland) //string filename = urlencoder.encode(url); file f = new file(cachedir, filename); homecoming f; }

so, should utilize string filename = urlencoder.encode(url);??

and

//use 25% of available heap size

by heap size mean ram? or max ram can allocated applcation (i read somewhere 19mb).

because according device(samsung galaxy gt-s5830) specifications:

internal- 158 mb storage, 278 mb ram

but in log get

01-23 06:23:45.679: i/memorycache(1712): memorycache utilize 16.0mb

which 25% set in code.

if 25% of available memory. in settings -> applications -> manage applications:

at bottom, says 159mb used 21mb free.

thankyou

the reason, author mentioned utilize 1 imageloader class through out application many time create imageloader class instance internally creates memorycache object means 10 times imageloader instance 10 times memorycache objects. in lazylist project, 1 memorycache object reserves 1/4th of app heap memory images. here of app heap memory exhausted due many memorycache instances. here have solution problem create memorycache class singleton class in below code:

change constructor in memorycache private , next modifications.

private static memorycache mc; public static memorycache getmemorycache() { if(mc==null) { mc = new memorycache(); } homecoming mc; } private memorycache(){ //use 25% of available heap size setlimit(runtime.getruntime().maxmemory()/4); }

android lazy-loading

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -