I have an application with a service that downloads a set of job data
from a remote web service. It uses this data to update a static
HashMap of Job objects:

public static HashMap<String, Object> jobs = new HashMap<String,
Object>();

When it's finished, it sends a message to a handler in
MapViewActivity:

MapViewActivity.handler.sendMessage( new Message() );

to tell it redraw markers on the map based on the data in the jobs
HashMap :

public class MapViewActivity extends MapActivity {
   private static HashMap<String, Object> markers = new
HashMap<String, Object>();

    public static Handler handler = new Handler() {
        public void handleMessage( Message m ) {
            super.handleMessage( m );
            syncMarkers();
        }
    };

syncMarkers() reads the jobs HashMap and updates the markers HashMap
based on what it finds. The markers HashMap contains a mapping of
string identifiers to MapOverlay (which extends ItemizedOverlay)
objects.

I'm getting a java.util.ConcurrentModificationException and a force
close from within  syncMarkers() as it tries to iterate over the
markers HashMap. I can see from the backtrace that syncMarkers() is
being invoked from the handler.

I presume this is because the user interface is trying to access the
marker objects at the same time as syncMarkers(). However, I'm very
surprised that this is the case, because I thought the handler would
run in the same thread as the user interface (and not the service's
thread), and so would never conflict. Am I wrong?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to