I built an application where I display several charts in a tabbed layout (using ActionBar tabs) using androidplot library
On each tab I show a single chart inside a fragment. Since it is pretty slow to render (I have series of 3000/4000 values) when I switch tabs, I tried to put the graph generation in a background thread using AsyncTask.
It works properly, but I noticed if I use an indeterminate ProgressBar, the indicator is not spinning but it remains still, meaning there is some process blocking the UI thread. (my guess here).
Do you have any suggestion about how can I improve my application? I'd like to show the ProgressBar as loading indicator instead of still text
Here is the AsyncTask code, where I ended up using a "Calculating..." message instead of a ProgressBar as a workaround:
private class AsyncPlotTask extends AsyncTask<XYPlot, Void, Boolean> {
@Override
protected void onPreExecute() {
//show loading message only
loading.setVisibility(View.VISIBLE);
dataContainer.setVisibility(View.GONE);
}
@Override
protected Boolean doInBackground(XYPlot... plot) {
boolean success = true;
plot[0].addSeries(dataSeries, dataSeriesFormat);
return success;
}
@Override
protected void onPostExecute(Boolean result) {
//hide loading message and show graph
loading.setVisibility(View.GONE);
dataContainer.setVisibility(View.VISIBLE);
}
}//AsyncPlotTask
It looks like there is not a perfect solution
I ended up having a ProgressBar instance in the Activity, another instance in each fragment exactly overlapping the Activity one and then I just fade them in and out.
The "stuck" effect is now negligible