Need best practice advice for using several maps in an Android app

Discussion created by fredrikp on Jan 25, 2012
Latest reply on Jul 31, 2017 by ANohe-esristaff
I need to display a map several places in an Android app. My problem is that the first map I create works fine, but the second one will not display the current position or any graphic markers. The maps are in different activities.

I have tried to call map.recycle() when pausing the first activity, and this makes the second map display the graphic markers, but then I need to recreate the first map all over again, which causes me to think that I am going the wrong way about this. 

The code used to create the maps are identical in the two activities, except for the resource IDs which are different.

What is the best way (or correct way) to have two maps active in two different activities in the same app? What should be done in the onCreate, onDestroy, onPause and onResume?

Example code:

// Credentials to access the map
String tokenServiceUrl = "https://somewhere/arcgis/tokens";
String userName = "secret";
String password = "secret";
UserCredentials credentials =  new UserCredentials();
credentials.setUserAccount(userName, password);
// Initialize the map
map = (MapView) findViewById(;
String mapUrl = "http://path_to_mapserver";
ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(mapUrl, credentials);
graphicsLayer = new GraphicsLayer();

Then I set up a setOnStatusChangedListener, wait until I get INITIALIZED, then add graphic markers and start localization. When receiving location changed, I zoom the map to the current location.

Any help will be greatly appreciated!