java - Android string content loading performance -


i have 1000 lines in file served user every time he/she loads application.

my current approach is:

mainactivity: oncreate: start asynctask

asynctask onpreexecute: show progress dialiog

asynctask doinbackground: check if key/value present in sharedpreferences, if yes, nothing in doinbackground. if no (first time user), read raw file , create stringbuilder. store content of stringbuilder key value pair in sharedpreferences.

asynctask onpostexecute: populate textview sharedpreferences. dismiss progress dialog.

the code read file in doinbackground method is:

stringbuilder sb = new stringbuilder(); inputstream textstream = getbasecontext().getresources().openrawresource(r.raw.file); bufferedreader breader = new bufferedreader(new inputstreamreader(textstream));  string ajsonline = null; try {     while ((ajsonline = breader.readline()) != null) {         sb.append(ajsonline + system.getproperty("line.separator"));     } } catch (ioexception e) {     e.printstacktrace(); } finally{     try {         breader.close();         textstream.close();     } catch (ioexception e) {         e.printstacktrace();     } } 

i seeing user has wait around 9-10 seconds first launch , 4-5 seconds subsequent launches. suggestions improve performance in case.

you don't need make user wait whole list loaded. once have enough data fill screen (10-20 items, maybe?), populate onscreen list or whatever data have, make delay totally insignificant.

you may check http://developer.android.com/reference/android/content/asynctaskloader.html see how it's supposed done.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -