(Android)Map is not displayed after coming back to foreground
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.1.2-beta-20180111-1339" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.1.2-beta-20180111-1605" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/CordovaGoogleMaps.java
src/android/plugin/google/maps/CordovaGoogleMaps.java
@@ -445,6 +445,7 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
Runtime.getRuntime().gc();
callbackContext.success();
}
+
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void getMap(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
//------------------------------------------
@@ -464,85 +465,66 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
pluginMap.getMap(args, callbackContext);
}
- @Override
- public void onPause(boolean multitasking) {
- super.onPause(multitasking);
- cordova.getThreadPool().submit(new Runnable() {
- @Override
- public void run() {
- Set<String> mapIds = mPluginLayout.pluginMaps.keySet();
- PluginMap pluginMap;
+ @Override
+ public void onStart() {
+ super.onStart();
- // prevent the ConcurrentModificationException error.
- String[] mapIdArray= mapIds.toArray(new String[mapIds.size()]);
- for (String mapId : mapIdArray) {
- if (mPluginLayout.pluginMaps.containsKey(mapId)) {
- pluginMap = mPluginLayout.pluginMaps.get(mapId);
- pluginMap.mapView.onPause();
- }
+ Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
+ for (PluginEntry pluginEntry: pluginEntries) {
+ if (pluginEntry.service.startsWith("map_")) {
+ pluginEntry.plugin.onStart();
}
}
- });
- }
+ }
@Override
- public void onResume(boolean multitasking) {
- super.onResume(multitasking);
- if (mPluginLayout != null) {
- mPluginLayout.isSuspended = false;
+ public void onStop() {
+ super.onStart();
- if (mPluginLayout.pluginMaps.size() > 0) {
- this.activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- CURRENT_URL = webView.getUrl();
- webView.loadUrl("javascript:if(window.cordova){cordova.fireDocumentEvent('plugin_touch', {});}");
- }
- });
+ Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
+ for (PluginEntry pluginEntry: pluginEntries) {
+ if (pluginEntry.service.startsWith("map_")) {
+ pluginEntry.plugin.onStop();
}
}
- cordova.getThreadPool().submit(new Runnable() {
+ }
@Override
- public void run() {
+ public void onPause(boolean multitasking) {
+ super.onPause(multitasking);
- Set<String> mapIds = mPluginLayout.pluginMaps.keySet();
- PluginMap pluginMap;
+ Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
+ for (PluginEntry pluginEntry: pluginEntries) {
+ if (pluginEntry.service.startsWith("map_")) {
+ pluginEntry.plugin.onPause(multitasking);
+ }
+ }
- // prevent the ConcurrentModificationException error.
- String[] mapIdArray= mapIds.toArray(new String[mapIds.size()]);
- for (String mapId : mapIdArray) {
- if (mPluginLayout.pluginMaps.containsKey(mapId)) {
- pluginMap = mPluginLayout.pluginMaps.get(mapId);
- pluginMap.mapView.onResume();
}
+
+ @Override
+ public void onResume(boolean multitasking) {
+ Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
+ for (PluginEntry pluginEntry: pluginEntries) {
+ if (pluginEntry.service.startsWith("map_")) {
+ pluginEntry.plugin.onResume(multitasking);
}
}
- });
+
}
@Override
public void onDestroy() {
super.onDestroy();
- cordova.getThreadPool().submit(new Runnable() {
- @Override
- public void run() {
-
- Set<String> mapIds = mPluginLayout.pluginMaps.keySet();
- PluginMap pluginMap;
-
- // prevent the ConcurrentModificationException error.
- String[] mapIdArray= mapIds.toArray(new String[mapIds.size()]);
- for (String mapId : mapIdArray) {
- if (mPluginLayout.pluginMaps.containsKey(mapId)) {
- pluginMap = mPluginLayout.pluginMaps.get(mapId);
- pluginMap.mapView.onDestroy();
+ Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
+ for (PluginEntry pluginEntry: pluginEntries) {
+ if (pluginEntry.service.startsWith("map_")) {
+ pluginEntry.plugin.onDestroy();
}
}
- }
- });
+
}
protected void sendNoResult(CallbackContext callbackContext) {

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -386,6 +386,32 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
});
}
+ @Override
+ public void onStart() {
+ super.onStart();
+ mapView.onStart();
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ mapView.onStop();
+ }
+
+ @Override
+ public void onPause(boolean multitasking) {
+ super.onPause(multitasking);
+ mapView.onPause();
+
+ mapCtrl.mPluginLayout.removePluginMap(this.mapId);
+ }
+ @Override
+ public void onResume(boolean multitasking) {
+ super.onResume(multitasking);
+ mapView.onResume();
+ mapCtrl.mPluginLayout.addPluginMap(PluginMap.this);
+ }
+
private class AdjustInitCamera implements Runnable {
private JSONObject mParams;
private CallbackContext mCallback;

(Android)Map is not displayed after coming back to foreground #1980