Hi,
we have a problem with switching basemaps in our Android app.
We have two different types of basemaps (both are ArcGISTiledMapServiceLayers, based on MapServices published to our ArcGIS Server).
Initially, the map is loaded with the first basemap (basemapOne) on top of it:
ArcGISTiledMapServiceLayer baseMapOne = new ArcGISTiledMapServiceLayer(basemapURL1);
map.addLayer(baseMapOne);
However, the user can toggle a switch to change to the other basemap.
We have implemented this as follows (layer number 0 is the first layer, i.e. the basemap):
map.getLayer(0).recycle();
map.removeLayer(0);
if (...basemapOne was switched on....) {
map.addLayer(new ArcGISTiledMapServiceLayer(basemapURL1), 0);
} else {
map.addLayer(new ArcGISTiledMapServiceLayer(basemapURL2), 0);
}
Sometimes this works without problems, especially if we only just started the app. But if we then, for example, press the home button and thus pause the map, reopen it, and try to switch the basemap, nothing happens - the basemap we try to remove remains visible. Sometimes, we can see a few single tiles of the second basemap "shining through" , but that's all.
The only thing that helps in this case is to clear the app from memory, or to completely close it by using the back button. If we then open it again, switching basemaps usually works again (but sometimes not even then). It seems that the old tiles are still cached somehow, or not cleared from memory when calling "map.removeLayer". Or could it have to do with the fact that we use
getSharedPreferences(
"mapPreference", 0).edit().putString("mapState", map.retainState()).apply();
to save the map state in onPause(), and map.restoreState(mapState) in onResume ?
By the way, the same problem appears if we don't use "removeLayer" and "addLayer" but instead setVisibility(true/false).
Any ideas how to solve the problems? Thank you!