I have a class which extends MapActivity.

I have pins which I place on the map using a function called updateMap.The pins are placed in locations based on a list of bus stops that are loaded in. 

I would like to show a loading dialog while the array of stops is downloaded but I get errors with my code. I currently have the dialog popping up and a thread spawning to load the bus routes and update the map.

After some research I've come to realize that the UI layer can't be updated from a separate thread. I've tried moving things around but nothing seems to work.

Any help appreciated!

```
private void updateMap(final int selectedRoute, final boolean isMajor, final boolean isMinor)
{
    dlg = ProgressDialog.show(TransitMap.this, "Updating Map", "Processing... Please wait...");
    new Thread()
    {
        public void run()
        {
            try 
            {
                TransitMap.this.removePins();
                TransitMap.this.addRoutePins(selectedRoute, isMajor, isMinor);
                TransitMap.this.addBusPins(selectedRoute);

                map.post(new Runnable()
                {   
                    public void run()
                    {
                        TransitMap.this.map.postInvalidate();
                    }
                });
            }
            catch(Exception ex)
            {
        }
            // processing done, hide progress dialog
            dlg.dismiss();
        }
    }.start();
}

```

After modifying the class to use AsyncTask, I still have my program crashing!

This is the logCat error

```
04-13 15:16:49.217: E/AndroidRuntime(21898): FATAL EXCEPTION: main
04-13 15:16:49.217: E/AndroidRuntime(21898): java.util.ConcurrentModificationException
04-13 15:16:49.217: E/AndroidRuntime(21898):    at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:576)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:44)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at com.google.android.maps.MapView.onDraw(MapView.java:530)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.View.draw(View.java:6971)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1708)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.drawChild(ViewGroup.java:1710)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1437)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.View.draw(View.java:6974)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1929)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewRoot.draw(ViewRoot.java:1590)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1290)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1939)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.os.Looper.loop(Looper.java:143)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at android.app.ActivityThread.main(ActivityThread.java:4196)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at java.lang.reflect.Method.invokeNative(Native Method)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at java.lang.reflect.Method.invoke(Method.java:507)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-13 15:16:49.217: E/AndroidRuntime(21898):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
04-13 15:16:49.217: E/AndroidRuntime(21898):    at dalvik.system.NativeStart.main(Native Method)

```