(Android) prevent the java.util.ConcurrentModificationException error
MODIFY
src/android/plugin/google/maps/MyPluginLayout.java
src/android/plugin/google/maps/MyPluginLayout.java
@@ -234,6 +234,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
public void clearHtmlElements() {
Bundle bundle;
RectF rectF;
+ synchronized (HTMLNodes) {
String[] keys = HTMLNodes.keySet().toArray(new String[HTMLNodes.size()]);
for (int i = 0; i < HTMLNodes.size(); i++) {
bundle = HTMLNodes.remove(keys[i]);
@@ -243,6 +244,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
}
keys = null;
}
+ }
public void putHTMLElements(JSONObject elements) {
@@ -276,8 +278,10 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
HashMap<String, Bundle> oldBuffer = HTMLNodes;
HashMap<String, RectF> oldBufferRectFs = HTMLNodeRectFs;
+ synchronized (HTMLNodes) {
HTMLNodes = newBuffer;
HTMLNodeRectFs = newBufferRectFs;
+ }
String[] keys = oldBuffer.keySet().toArray(new String[oldBuffer.size()]);
for (int i = 0; i < oldBuffer.size(); i++) {
@@ -500,6 +504,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
boolean isMapAction = false;
+ synchronized (HTMLNodes) {
while (iterator.hasNext()) {
entry = iterator.next();
mapId = entry.getKey();
@@ -566,6 +571,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
break;
}
}
+ }
isScrolling = (!isMapAction && action == MotionEvent.ACTION_DOWN) || isScrolling;
isMapAction = !isScrolling && isMapAction;
@@ -588,6 +594,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
Iterator<Map.Entry<String, PluginMap>> iterator = pluginMaps.entrySet().iterator();
Entry<String, PluginMap> entry;
RectF mapRect;
+ synchronized (HTMLNodeRectFs) {
while (iterator.hasNext()) {
entry = iterator.next();
pluginMap = entry.getValue();
@@ -599,6 +606,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
debugPaint.setColor(Color.argb(100, 0, 255, 0));
canvas.drawRect(mapRect, debugPaint);
}
+ }
}

(Android) prevent the java.util.ConcurrentModificationException error