Hello World

Complexity: Beginner Data Requirement: ArcGIS.com

This sample demonstrates an Android application with map viewer. The application loads a worldwide street cached data map on an Android device with zoom in, zoom out, and pan operations. This is achieved by adding a MapView object, which is the main mapping component of the ArcGIS API for Android.

How to use

See How to work with samples for more information on running this sample on Eclipse IDE.

The class is based on Android's Activity class and calls the onCreate() method to perform. Android activity is overridden to include map control.

public class HelloWorld extends Activity {

	MapView map = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		map = (MapView) findViewById(R.id.map);

The initial extent for the map to zoom is set in res\layout\main.xml.

<?xml version="1.0" encoding="utf-8"?> 
	    <com.esri.android.map.MapView 
xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/map" android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     initExtent="-1.3296373526814876E7 3930962.41823043 -1.2807176545789773E7 4201243.7502468005">

The map center and resolution is preserved by the onRetainNonConfigurationInstance method and restored with the onCreate method. This helps maintain the map's desired state to propagate to the next activity instance.

/** Called by the system, as part of destroying an activity due to a configuration change. */
	@Override
	public Object onRetainNonConfigurationInstance() {
		return map.retainState();
	}

You can retrieve the map's state from the previous instance with the getLastNonConfigurationInstance method.

/** Called by the system, as part of destroying an activity due to a configuration change. */
		Object init = getLastNonConfigurationInstance();
		if (init != null) {
			map.restoreState((String) init);

You have a map viewer application running on Android. Here is a list of actions you can try to see how zoom and pan operations work by default:

1/24/2013