AnsweredAssumed Answered

Switching basemaps in Android app not working properly

Question asked by lageplan on Jul 27, 2016
Latest reply on Jul 29, 2016 by lageplan



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);



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):





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



   "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!