Using ASYNC Task to load map pins
<p>I've been successful at adding map pins to my map overlay but it loads slow and moving around the map is sluggish. I am thinking it is when it is downloading the map pins from the server. The pins are only about 20-30 kb in size, but at times are may be 25 pins to add. I have already tried to add the pins in the background but it will break the app. What can I do to add the pins in the background without affecting performance?</p>

<p>I get the location from map when the user touches the map and executes this ASYNC task.</p>

<pre><code>    private class mapStations extends AsyncTask&lt;Void, Void, JSONObject&gt; {

    @Override
    protected JSONObject doInBackground(Void... arg0) {

        JSONObject obj = null;
        try {
            obj = new JSONObject(API.nearByStations(pxLat, pxLng, 0));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return obj;
    }

    @Override
    protected void onPostExecute(JSONObject details) {
        String tag = "mapStations";
        JSONArray stations;
        Drawable d = null;
        try {
            mapOverlays = mapView.getOverlays();
            mapOverlays.clear();
            stations = details.getJSONArray("stations");

            for (int j = 0; j &lt; stations.length(); j++) {
                JSONObject jsonObject = stations.getJSONObject(j);
                Log.i(tag, "url: " + jsonObject.getString("logo"));
                try {

                    Bitmap staticImage = BitmapFactory
                            .decodeStream((InputStream) new URL(jsonObject.getString("logo"))
                                    .getContent());
                    d = new BitmapDrawable(staticImage);

                } catch (MalformedURLException e) {
                    Log.e(tag, e.toString());
                    e.printStackTrace();
                } catch (IOException e) {
                    Log.e(tag, e.toString());
                    e.printStackTrace();
                }
                add(jsonObject.getDouble("lat"),
                        jsonObject.getDouble("lng"), d);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}

public void add(double lat, double lng, Drawable d) {

    mapOverlays = mapView.getOverlays();
    if(d.equals(null)){
        Log.i(tag, "d was null");
        d = this.getResources().getDrawable(R.drawable.androidmarker);
    }

    itemizedOverlay = new MapsOverlay(d);

    GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6));
    OverlayItem overlayitem = new OverlayItem(point, "", "");

    itemizedOverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedOverlay);
}
</code></pre>

<p>This is the logcat from adding the points in the doinbackground. It doesn't happen every time but it does happen. I can't seem to reproduce when it happens either. Sometime it happens when I zoom out, sometimes it happens when I move around the map. I had similar question about this here <a href="http://stackoverflow.com/questions/8565385/android-mapview-json-array-adding-array-of-points">Android MapView JSON Array Adding Array of points</a> but I ended up moving it to the post execute. Like I mentioned before it takes awhile to load the pins. I am kind of at a loss write now. I have been working on this all day.</p>

<pre><code>    [12-23 13:46:27.246: E/AndroidRuntime(1359): Uncaught handler: thread main exiting due to uncaught exception
12-23 13:46:27.286: E/AndroidRuntime(1359): java.util.ConcurrentModificationException
12-23 13:46:27.286: E/AndroidRuntime(1359):     at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:41)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at com.google.android.maps.MapView.onDraw(MapView.java:476)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.View.draw(View.java:6535)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.View.draw(View.java:6538)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.View.draw(View.java:6538)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.widget.FrameLayout.draw(FrameLayout.java:352)][1]
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.View.draw(View.java:6538)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewRoot.draw(ViewRoot.java:1349)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.os.Looper.loop(Looper.java:123)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at android.app.ActivityThread.main(ActivityThread.java:4363)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at java.lang.reflect.Method.invokeNative(Native Method)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at java.lang.reflect.Method.invoke(Method.java:521)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-23 13:46:27.286: E/AndroidRuntime(1359):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>
