Android App Development: Getting Started


Recently my family became a two mobile platform household: iPhone and Android.  As an educator and developer, I am interested in supporting all platforms equally.  So, to support those members of my family (and anyone else interested in developing for the Android platform) I am starting a series of articles on Android App development.

I have found developing for Android apps very appealing:

First, the development is in Java (which is my preferred programming language).

Second, since we are using Java, we can use Eclipse for our IDE (again, my preferred IDE).

Third, beyond getting everything initially configured, it doesn’t make any difference whether you are developing on Linux, Mac, or Windows.  If you have a computer, you can develop for the Android.  You don’t have to buy a specific brand of hardware to get started.

Fourth, Google has followed Apple’s lead on setting a nice transaction fee to attract developers.  Google charges a 30% transaction fee, you (the developer) get 70%!


Wirefly: DROID X by Motorola Coming July 15th

Fifth, it only cost $25 to become a developer.

And the list goes on and on… so let’s forget about the reasons why we want to develop an Android app and start developing!

Installations

The installation process on this is somewhat long (especially compared to Apple’s xCode), but it is a one-time process.

If you’re going to develop for Android, you have to have the right software.

First, download the latest JDK (Java Developers Kit) from Sun: http://java.sun.com/javase/downloads/index.jsp The recommended package is Java SE (Standard Edition).  Just select the JDK and you will be taken to a widget to download the correct version for your OS.

Second, download Eclipse IDE from http://www.eclipse.org/downloads/ and select Eclipse for Java Developers.  Then just select your OS.

Finally, download the Android SDK: http://developer.android.com/sdk/index.html

Unzip the Android SDK and remember where you saved the files (I placed mine in the Applications folder on my Mac, Program Files on my PC).  If you want to configure the path to make getting to the SDK tools and installing the Android Development Tools (ADT), you can find concise directions at http://developer.android.com/sdk/installing.html#Installing

ADT

The Android Development Tools (ADT) are a set of extensions for Eclipse that make developing for an Android device much easier.
If you’re going to use Eclipse to develop Android apps, you need to install ADT.

Adding ADT to your Eclipse install is easy.  Just click Help > Install New Software.

Click on the ADD button, and enter Android Development Tools for the name and https://dl-ssl.google.com/android/eclipse/ for the location. If you have problems with the install, you might try it the install as http instead of https.

Select the Developer Tools in the next dialog, read and accept the license agreement, and click Finish.

Configure the ADT
Now we need to the let the ADT know where the SDK is installed.  This accomplished in the Preferences (Eclipse > Preferences on the Mac, Window > Preferences in Windows).  Select Android, then in the SDK Location area, browse to where you installed the SDK.

Components
The final step before we can program is to use the Android SDK and AVD (Android Virtual Devices) Manager to install needed components.  Don’t skip this step! You need some virtual devices and SDK components to be able to make everything work!

To launch, in Eclipse, go to Window > Android SDK and AVD Manager.   In the dialog box, select Available Packages in the left column, and then select all of the packages in the right window (no sense in messing around!).   Click Install Selected. You may have to agree to some of the packages.


Hello World!

If you are new to Java, I suggest that you review my tutorials on using Java and the Eclipse IDE before you go to much further.  I am in the process of putting an full Introductory course and Intermediate course in Java on my blog (http://www.burtonsmediagroup.com/blog/category/java/)

If you’re ready, let’s do some coding!

First, we will setup the AVD.

Go to Window> Android SDK and AVD Manager. Select Virtual Devices in the left window, and click New.

The Create New AVD dialog window will open.   Name it ‘my_avd’.

Select the target platform (which version of Android you are developing for, in my case 2.2).

You can ignore the rest of the fields for now, just click Create AVD.

Close the manager.

Click File > New > Project.  If the ADT is properly installed, you should see Android in the list of choices.  Select Android, which should show Android Project as a subcategory.  Select Android Project and click Next.

In the dialog box, enter:

Project Name: HelloWorld    (NO SPACES!)

Application Name: Hello World   (Spaces are okay)

Package Name: com.example.HelloWorld  (or your name space, mine is com.burtonsmediagroup.helloworld)

Create Activity: HelloWorld   (NO SPACES)

And click Finish

In your Package Explorer window, you should be able to open the HelloWorld Project > src > com.example.helloworld > HelloWorld.java

If you double click on HelloWorld.java, it will open in the main window with:

package com.burtonsmediagroup.helloworld;

import android.app.Activity;
import android.os.Bundle;

public class HelloWorld extends Activity {
/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

This is the base code for your Android project.  It doesn’t do anything.. yet.

Under the import statements, add:
import android.widget.TextView;

Under

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Add:
TextView tv = new TextView(this);
tv.setText(“Hello World”);
setContentView(tv);

Before the }

And that’s it!  You have code the ‘Hello World’ project!

Go ahead and run it (as an Android Project) Run > Run You should see the simulator start and eventually your project will run (you can see its progress in your console at the bottom of the Eclipse IDE).

What did we just do?
The 4 lines of code we just added were very important.

1)   the import android.widget.TextView;  – loaded the correct tools for us to call to display the text ‘Hello World’

2)   TextView tv = new TextView(this); created a new TextView object, tv, (if you have been programming in Java for any length of time, this should look normal to you).

3)   tv.setText(“Hello World”);   sets the setText property of tv to “Hello World”

4)   setContentView(tv);   tells the User Interface to display tv.

And there we have it!  You have successfully created your first Android App!  Woot!
[tubepress video=”SzdDEscjIJ8″]

Recent Posts