Android Tutorials
Working With Android Contacts
Accessing Data With Android Cursors
Creating Lists Using The Android ListActivity
Android 9 Patch Scaled PNG Image Guide
Working With Images In Android
Exploring Android LinearLayout And RelativeLayout
Writing A Basic Android Application
Installing The Android SDK In Eclipse

Writing A Basic Android Application

Working with the AndroidManifest.xml File

Now that we've added a new view we need to create an associated activity. Activities need to be registered in the AndroidManifest.xml file. When the project was created we defined an activity TestApp. This was setup as an activity for the application in the AndroidManifest.xml file when the project was created. Bring up the XML by clicking the AndroidManifest.xml tab at the bottom of the main pane.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TestApp"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
<uses-sdk android:minSdkVersion="5" />

Notice the manifest starts with the standard xml tag. Then there is a manifest tag that links to the schema and defines the package, versionCode, and versionName attributes. Nested inside the manifest tag is an application tag. The application tag has the attributes android:icon and android:label that define the applications icon and the label respectively. The application tag contains the activity nodes that define the accessible activities of the application.

When the project was created the first activity for TestApp was pre-populated into the file. Notice the android:name value starts with a "." this is because it's the class that's appended to the package name. The label for the activity is set to the app_name string from strings.xml.

The intent-filter tag is used to declare the intents for the activity. An intent is simply a tag defining an attributes of the activity. The action tag with a name of "android.intent.action.MAIN" will declare the activity as the initial activity. The category tag with a name of "android.intent.category.LAUNCHER" allows the activity to be an initial activity and will list the activity in the Android application launcher.

We need to declare a second activity. Click on the Application tab at the bottom of the pane. Scroll to the bottom of the page to expose all of the Application Nodes and Attributes for Activity sections. Click Add under Applicaton Nodes. In the dialog select Activity and click OK. Now select the new activity and update the section under Attributes. First set the name to Relative then the label to @string/app_name. Click on the activity and save the file.
Eclipse Install Android SDK Continued

There will be an error in the file until we create the Relative activity class in a minute. Before creating the Relative activity class take a second to explore the XML created by adding the new activity. Click back to the AndroidManifest.xml tab at the bottom of the main pane. You should see a new activity tag that looks like the following.

 <activity android:name="Relative"

The activity tag simply gives the activity a name and declares a label for the window.

LinerLayouts, Linear and Relative <<  1 2 3 4 5  >> Building The Android Code
New Content