Вопрос

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
Это было полезно?

Решение 2

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

Другие советы

Here's what it sounds like to me:

By default Androidplot uses the main thread for rendering, which is fine for most plots with a few dozen points but with plots containing a few thousand points as you've experienced it takes time. While the main thread is engaged to render the plot the UI will not update - this includes updating progress bars.

Setting your plot to render using background mode should solve the issue. If you are using Androidplot 0.5.1 or later you can enable the background rendering thread by adding this to your plot's xml:

renderMode="use_background_thread"

Nick

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top