java - Most appropriate way to load data from internet into listview -
i have simple query have been picking mind around lot lately without straight solution. have listview loads quote data internet. list item bit complex not problem . listview loaded using loader fetches quote data internet, parses json , populates vos. list of vos set in adapter , notifydatasetchanged
changed called reloads list through adapter's getview
now pattern have used here is:
- user clicks button, open fragment
- the fragment has
loadercallbacks
, initiate loader inonactivitycreated
- the loader has cached thread pool executor (i cant use async loaders use linear loading not parallel across android api versions) creates download worker each stock.
- the worker hits url , downloads data, parses json using gson, creates object , puts in loader's arraylist.
- loader uses latch wait till quotes downloaded.
- once done list loaded.
my problem when listview has lots of stocks, 70 90 quote downloading process becomes slow. on direct wifi network takes 1.5 2 seconds list load. on mobile data networks 2g , 3g , hybrids takes 30-40 seconds load. profiling shows majority time spend in reading data stream. each quote url hit 700-800 bytes , takes 800-900ms load. using httpurlconnection
load urls.
i cannot use dynamic loading pattern in list have menu items filter , sort listview. wont make sense if don't have quote data in list in first place.
is there better way this? have read things around , have tried "new async task each row in list when row becomes visible on screen" cant use such mean lazy loading of data.
edit show how data deserialized:
inputstream inputstreamobj = (inputstream) conn.getcontent();//getinputstream(); if(inputstreamobj != null){ reader reader = new inputstreamreader(inputstreamobj); gsonbuilder gsonbuilder = new gsonbuilder(); gsonbuilder.registertypeadapter(list.class, new companycorpannouncementsvodeserializer()); gson gson = gsonbuilder.create(); retval = gson.fromjson(reader, list.class); }
for reading , have similar issues, use paginated 'load more stuff on scroll end' design instead of breaking list pieces. ended using full throttled load backed cached threadpool executor when on wifi or 3g/4g , falling fixed thread pool executor of 2 threads , loading 6 @ time when on other network. works great me.
Comments
Post a Comment