Run this ArcGIS Android Program
I have spent half a day working on the environment, construction, and advertisement placement. I am so tired ...... It's time to look at the real thing! Now let's run "agssamplehelloworld ".
Figure 14 debug the android Program
Similar to a general Java program, the running type is Android Application. To run an android program, you need a simulator or a real device. If you want to use a simulator, you can select the new AVD:
Figure 15 select a simulator
It takes a lot of time to start the simulator for the first time. After the simulator is started successfully, you can see the running results of the "agssamplehelloworld" project. Although nothing special can be seen, but does the "helloworld sample" mentioned above appear as expected in the title position?
Figure 16 run the hello World Program on the android Simulator
In addition, a map is now displayed, and a map control is added to the map service. Now, let's see how this "agssamplehelloworld" map is displayed.
Figure 17 debugging options of the hello World Program
From the debugging options of the "agssamplehelloworld" project, we can see that when we run the program, the program runs the default activity. In the previous section, the activity is not described due to the time relationship, here we will insert a short section of Android activity content.
An activity is an interface that the android program presents to the user. All interactions with the user occur in the activity. To some extent, the android activity is similar to a form of a Windows program. For more details about the activity, see http://androidappdocs-staging.appspot.com/reference/android/app/activity.html. OK. The insertion ends.
When we run the "agssamplehelloworld" program, the default activity (COM. ESRI. ArcGIS. Android. sample. helloworld) is actually run. The source code of this activity is as follows:
PackageCom. ESRI. ArcGIS. Android. samples;
ImportAndroid. App. activity;
ImportAndroid. OS. Bundle;
ImportCom. ESRI. Android. Map. mapview;
Public ClassHelloworldExtendsActivity {
Mapview map =Null;
/** Called when the activity is first created .*/
Public VoidOncreate (bundle savedinstancestate ){
Super. Oncreate (savedinstancestate );
Setcontentview (R. layout.Main);
Map = (mapview) findviewbyid (R. Id.Map);
Object init = getlastnonconfigurationinstance ();
If(Init! =Null){
Map. restorestate (string) Init );
}
}
/** Called by the system, as part of destroying an activity due to a configuration change .*/
PublicObject onretainnonconfigurationinstance (){
ReturnMap. retainstate ();
}
}
When you run an android program and call an activity for the first time, the oncreate method is called first (For details, refer to the activity lifecycle). In the oncreate method, the following code is the first thing to do:
Setcontentview (R. layout.Main);
The setcontentview method is used to generate a real activity object based on an XML layout file. We have already introduced this "r", "R. layout. the resource corresponding to main is "Main. the layout defined by the XML file (this layout file is somewhat similar to the flex mxml or Silverlight XAML, isn't it ?). Let's take a look at the content of "Main. xml:
& Quot; 1.0 & quot; encoding ="UTF-8"?>
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">
Url =Http://services.arcgisonline.com/ArcGIS/rest/services/
World_street_map/mapserver"/>
The root component of this layout is mapview [1]. mapview is a Class Based on viewgroup (which can be used as a container of other views or viewgroups) in Android, the ArcGIS Android API uses mapview as the map container, which is the same as the map and mapcontrol classes in many ArcGIS APIs.
In mapview, an arcgistiledmapservicelayer layer is added. Its URL attribute corresponds to the rest interface of a slice map service, the definition here is consistent with that of many ArcGIS Web APIs.
Mapview has an attribute of Android: ID, which is "@ + ID/Map ", this defines that the mapview in this XML will be interpreted as a mapview object with ID "map". Therefore, we can go back to "helloworld. the following code is displayed in the Java source file:
Map = (mapview) findviewbyid (R. Id.Map);
In Java code, you can use the findviewbyid method to obtain the mapview object in the current activity, or even any other view object.
So far, run the activity of the ArcGIS Android program, generate a mapview object according to the XML definition layout, and add an arcgistiledmapserviceslayer. The entire internal process of Hello world is over, the effect shown at the end is the same as that shown in Figure 16 at the beginning of this section.
[1] http://help.arcgis.com/en/arcgismobile/10.0/apis/android/api/com/esri/android/map/MapView.html