Issue
I'm trying to run a specific code that regularly adds/removes markers on a map, I tried the AsyncTask approach instead of thread and runnable,
in the doInBackground :
mapView.getOverlays.remove()
mapView.getOverlays.addOverlay(new overlay)
mapView.getController.animate(center point)
actual problem is, that code runs continuously and while executing map gets rendering and tries to get overlays to draw, while the code is removing and adding into the list, so ConcurrentModificationException is thrown and the application halts
I need help about it, I feel that I'm on the wrong path, what really should I use when trying to run code in background thread that updates regularly markers on the map ??
Solution
If you do not want to render the points all in one go like slkorolev suggested, use the UI handler mechanism.
Handler myHandler = new Handler() {
publicvoid handleMessage(Message msg) {
switch (msg.what) {
case TestHandler.NEW_OVERLAY_ITEM_EVENT:
mapView.getOverlays.remove()
mapView.getOverlays.addOverlay(new overlay)
mapView.getController.animate(center point)
break;
}
super.handleMessage(msg);
}
};
// post this UI update event
Message message = new Message();
message.what = TestHandler.NEW_OVERLAY_ITEM_EVENT;
TestHandler.this.myHandler.sendMessage(message);
Answered By - Reno
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.