Forgot your password?

Starting Android 2.2 development

By Edited Mar 25, 2014 1 0


Setting up the development enviroment

First of all, I assume you would like to learn how to program small applications for Android using the Eclipse Development Enviroment, and this just the start to an entire new world, where you hopefully will be able to make some interesting applications for mobile Android devices.

Now, to get you setup, you should start off with downloading the Android SDK from http://developer.android.com/sdk/. Once you have downloaded the Android SDK, you can follow the steps below on the same page to setup your Eclipse Development Enviroment.

Starting Your First Project

Creating the HelloWorld Project

As you have now setup the development enviroment completely, it's time to start programming your first application. To get a basic grasp of the structure of Android Applications, we will start off creating a Hello World program. This is a simple application, which can be used for nil, of course with the exception of printing "Hello World" on the screen.

To start your first Android project, press File -> New -> Android Project. A dialog will come up. This is where you'll have to name your project. For starters, let us just call it "HelloWorld". 

You will now have to select which version of Android you want to be developing towards, as the guide is about starting Android development on Android 2.2, we will choose Android 2.2 for our build target. Next up is choosing an application name, this is the name that appears on the device launcher screen. Again, for this field, we will just write "Hello World".

The package name is one of the required fields for starting an Android project, this is normally in reverse domain notation (meaning if your company domain or personal domain, is example.com, you will write it like com.example). As this is just an example, let us just say our domain is example.com, so we will type in "com.example", note that the package name is all lowercase, that is a good practice for programming Java applications in general.

The next field is Create Activity, which involves a checkbox too, for starters we will leave the checkbox checked, and you will now have to write an Activity name for the main activity of the application. For this exercise, we are just going to call it HelloWorldActivity.

The filled out form should look like below (or something similar)

Filled Out Create Project Dialog

Now you can click the Finish button, and Eclipse will generate the project files for you.

The Structure of an Android Application

This section will cover the basics regarding the structure of your Android Application.

If you look in the Package Explorer, you will notice that I have unfolded some of the directories.

Package Explorer

If we start from the top, you will notice the folder "src", this is where you will be writing your Java code for the main functions of your application.

The next folder is "gen", and there is a little text next to it saying "Generated Java Files", these files are generated by Ant (behind the scenes magic), and will contain Java links to files in your "res" folder, this folder will contain both your layout files, and a XML file containing your hardcoded values for your application, this makes the application much easier to translate, as it is just a matter of changing the text here instead of everywhere in your code.

These are the folders you will be working with during this guide.

Seeing the Source Code

Diving Into Programming

As we go into the "src" folder, and we locate our "HelloWorldActivity.java" file, we notice that the file itself does not contain a whole lot of code. This is mainly because it is just a simple application written to give something to work with. 

If we look closer on the other hand, we notice that the class contains a function named "onCreate", this function does not do a lot, but the last line inside the function, runs another function called "setContentView", and here it supplies the argument, "R.layout.main".

R is the class contained in the "gen" folder, so it is some that magic I described earlier. The R class is responsible for making your resources (located in your "res" folder), available to your Java code. If we look in our "res/layout" folder, we will notice that there is a file called "main.xml", this is the file that "R.layout.main" references, so to see what the content of our application is, we will have to open this file.

When you open it, you will notice that there is graphical user interface for designing your application. If you look at this, it should say "Hello World, HelloWorldActivity!" (if you named your activity "HelloWorldActivity").

Now if you choose to press the button in the bottom of the Eclipse main content area, labelled "main.xml", you will notice that the layout is specified in XML, it contains a linear layout, which then includes a text view, the text view element has an attribute called text, this attribute contains what will be shown on the screen, "@string/hello" is a link to another resource, which is loaded from a seperate xml file, found in "res/values". 

Once you have opened the "res/values/strings.xml" file, you will notice that Eclipse again has a graphical front end for configuring this xml file, and that you can access the raw XML by pressing the same button in the bottom of the screen, labelled "strings.xml" now.

This concludes the guide, I hope you liked it.



Add a new comment - No HTML
You must be logged in and verified to post a comment. Please log in or sign up to comment.

Explore InfoBarrel

Auto Business & Money Entertainment Environment Health History Home & Garden InfoBarrel University Lifestyle Sports Technology Travel & Places
© Copyright 2008 - 2016 by Hinzie Media Inc. Terms of Service Privacy Policy XML Sitemap

Follow IB Technology