performance - Draw a certain UI element only after it's fully loaded in Android -


i'm working viewpager in android.

every fragment represents element, plotted inside corresponding page using library (http://www.android-graphview.org/). if have been working viewpagers, know load 3 pages, 1 right, current 1 , 1 left. when start app, loads , draws 3 current plots (left, middle, right). every of these plots quite large, takes time load , draw them (about 3 seconds). if user swipes left, animation smooth, because 1 left preloaded , drawn. if user swipes left instantly again, graph not yet loaded , drawn, app freezes remaining time until data plotted.

question is: can achieve smooth animations while graphs loading in background, , plot them once finished loading? tried asynctask, manages crash app once in every while.

this oncreateview of page:

@override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment         view v = inflater.inflate(r.layout.fragment_pager_list, container, false);         view tv = v.findviewbyid(r.id.pagertext);         ((textview) tv).settext("fragment #" + mnum);         calendar date = new gregoriancalendar();         date.add(calendar.date, -29 + mnum);         log.d("date", string.valueof(-29 + mnum));         string datestring = (string.valueof(date.get(gregoriancalendar.year))) + "-"                 + (string.valueof(date.get(gregoriancalendar.month) + 1)) + "-"                 + (string.valueof(date.get(gregoriancalendar.day_of_month)));         //fill graph data current day         // sample data see if it's working dynamically.         dailycooldown cooldown = new dailycooldown(date.gettime());         graphview graph = (graphview) v.findviewbyid(r.id.graphtoday);         textview text = (textview) v.findviewbyid(r.id.textv1);         new plotgraphstask(graph, text, v.getcontext()).execute(cooldown);         // fill textviews below appropriate data         textview intensity = (textview) v.findviewbyid(r.id.intensity);         intensity.settext("intensity: " + string.valueof(cooldown.alpha2min));         textview dalda = (textview) v.findviewbyid(r.id.dalda);         dalda.settext("dalda scale: " + string.valueof(cooldown.dalda));         textview rpe = (textview) v.findviewbyid(r.id.rpe);         rpe.settext("rpe scale: " + string.valueof(cooldown.rpe));         return v;     } 

and asynctask i'm using:

private static class plotgraphstask extends asynctask<dailycooldown, void, void> {     public graphview graph;     public textview text;     public context context;     public plotgraphstask(graphview arggraph, textview argtext, context argcontext){         this.graph = arggraph;         this.text = argtext;         this.context = argcontext;     }     protected void doinbackground(dailycooldown... cooldown) {         graphview[] graphs = {graph};         textview[] labels = new textview[]{text};         visualizationsplotter.plot(cooldown[0].visualizations, graphs, labels, context);         return null;     } } 

the reason why app crashes doinbackground() method doesn't have connection ui thread, main thread of android app. , app freezes because plotting graphs in main thread (that takes time , freez application 3 secs).

but onprogressupdate() method have connection wuth ui thread, , can draw graph manualy, point point, method.


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 -