If the progress spinner in the ActionBar
is similar to ProgressDialog
, then yes it has to be run in its own thread to work. Luckily, AsyncTask
makes this really easy. An improvement I would suggest is doing your heavy lifting in a background thread. You could start by doing all of your database lookups and such in an AsyncTask
. You can still add the markers on the UI thread, but all of the data crunching will be done on a background thread. onPreExeecute()
, onProgressUpdate()
, and onPostExecute()
all execute on the UI thread, so it's safe to do UI operations there. Check out this snippet:
private class SetMarkersTask extends AsyncTask<Void, Marker, Void>
{
protected void onPreExecute()
{
// Turn progress spinner on
setProgressBarIndeterminateVisibility(false);
}
protected Void doInBackground(Void... params)
{
// Does NOT run on UI thread
// Long-running operation here; create a marker
publishProgress(myMarker);
}
protected void onProgressUpdate(Marker... params)
{
// Add newly-created marker to map
addMarker(params[0]);
}
protected void onPostExecute(Void result)
{
// Turn off progress spinner
setProgressBarIndeterminateVisibility(false);
}
}
This probably isn't exactly what you need, but it should give you an idea of how to structure your code using the progress spinner inside ActionBar
.