I am a Software Architect at IBM India Software Labs and part of the BPM product development team.In my spare time, I like to research on upcoming technologies and like to share my knowledge and experiences through blogs,articles, books and various forums.I am also a Master Author with IBM developerWorks,have co-authored books on Spring framework, the first book on Apache CXF and multiple IBM Redbooks.You can reach me on my website www.naveenbalani.com Naveen is a DZone MVB and is not an employee of DZone and has posted 7 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started with Android – Creating Android Application

02.15.2011
| 12255 views |
  • submit to reddit

This is ongoing blog on Getting Started with Android. In earlier blog, I provided an architecture overview of android application. In this blog, I will setup the development environment for Android and create a simple hello world application.

I would say are two ways you could develop Android applications-

  • The web development way: – Utilizing your web development skills like- HTML, CSS 3 and JavaScript (JQuery libraries). For instance, software’s like PhoneGap let you create web applications and uses a native bridge to run your applications to most leading mobiles- Android, IPhone and Blackberry.
  • Android SDK : – Using the Android SDK and third party android Java libraries to create applications using IDE like Eclipse.

I would start development with the later approach, but I plan to include web development also as part of this android series.

Here are the software’s you would need to create Android applications –

Eclipse IDE – I plan to use Eclipse IDE. You would need to install the Eclipse SDK “classic” platform. I have used the latest version 3.6. Download it from here.

Android SDK Starter Package – Download the android starter package windows installer from -http://dl.google.com/android/android-sdk_r08-windows.zip . The Starter package lets you choice and installs Android SDK components. Run the Android SDK Starter Package installer. The Android SDK Starter Package requires Java 5 or 6 and it would detect during installation. Once you install Android SDK Starter Package, run the SDK Manager.exe from installed location. On the Choose packages to install, click Cancel as we would install required packages only. Note that the applications developed on new versions of android are not backward compatible, for instance applications developed on 2.3 would not work on 2.2, but applications developed on 2.2 should continue to work on 2.3. (how ever this may no be the case always, so its best to test out the application on emulator).

Click on Available Packages and select SDK platform 2.3 (latest version) and Samples for SDK API 9 as shown   below. This would installed Android SDK and its dependent components.

Android ADT – Android development toolkit is an eclipse plug-in, which provides an integrated environment in eclipse for building and testing android applications. You can use the update manager in eclipse and install the ADT automatically or download the ADT Plugin zip from – http://dl.google.com/android/ADT-8.0.1.zip and install it manually. I prefer to use download the plug-in and install it manually. Once downloaded, follow these instructions –

  • Start eclipse . Click on Help -> Install New Software
  • Click on Add. In the Add Repository, Click Archive and provide the location of downloaded ADT zip file. Enter Name as ADT local. Click Ok
  • Click on Developer Tools and Click Next
  • Click Next. Accept the licenses and Click Finish.
  • This would install ADT plug-in. Restart eclipse
  • Next specify the location of Android
  • Click on Windows -> preferences

Next, Click on Android. In the Android preferences, click SDK location, click Browse and provide the location Android SDK location. Click Apply.

To check our installation was fine, we will create a hello world application and run it via Android emulator. Before running the Android application, you need to create an Android Virtual Device (AVD). AVD as the name suggest is a virtual device that emulates an android device and runs the application. The eclipse plug-in internally used android avd command, to create the AVD.

  • Click on Window > Android SDK and AVD Manager.  On the Virtual devices editor,Click New
  • Specify the Target as Android 2.3- API Level 9. (or the android environment which you want to create applications) , specify size of  SD card and skin for the emulator as shown below. Click Create AVD.

Once the AVD is created, we will create a simple hello world application by carrying out the following

  • Select File > New > Project.
  • Select Android > Android Project, Click Next.
  • Enter the following information for the project -

Project name –  WasuppAndroid

Build Target – Android 2.3

Application name –  Wasupp Android

Package name – org.android.samples

Create Activity –  Wasupp

Min SDK Version –  9

  • Click Finish

This would create a Project called WasuppAndroid in your workspace, Open up the Wasupp class and replace the onCreate method with the following onCreate() method as shown in listing below. Following shows the complete code listing.

package org.android.samples;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class Wasupp extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView tv = new TextView(this);

tv.setText("Wasupp, Android");

setContentView(tv);

}

}

 

This project would display – Wasupp, Android on the device when the application is executed. To build the project, select Project -> Clean

To run the WasuppAndroid Android application, click on it and select Run As > Android Application.

On the eclipse console, you would see the following similar message –

[WasuppAndroid] Performing org.andrroid.samples.Wasupp activity launch

[WasuppAndroid] Automatic Target Mode: launching new emulator with compatible AVD ‘AVD’

[WasuppAndroid] Launching a new emulator with Virtual Device ‘AVD’

[WasuppAndroid] Waiting for HOME (‘android.process.acore’) to be launched…]

You should see the Android AVD being launched. After the above message, it takes a while (2-3 minutes) for the first time to get the Android home page on the emulator.

After the device is started, you should see the following message on console..

[WasuppAndroid] Uploading WasuppAndroid.apk onto device ‘emulator-5554′

[WasuppAndroid] Installing WasuppAndroid.apk…

[WasuppAndroid] Success!

[WasuppAndroid] Starting activity org.andrroid.samples.Wasupp on device emulator-5554

If the application doesn’t show up on the emulator, Click on Menu option on the emulator and you would see the Wasupp android application and message being displayed.

 

With the environment up and running, in the next blog we will look at how to create Android applications.

Issues faced during running the AVD -

I got the following issue while running the AVD. I was using IBM JDK and had to switch it to Sun JDK to make the emulator work.

“- WasuppAndroid] Failed to install WasuppAndroid.apk on device ‘emulator-5554!
- WasuppAndroid] (null)
- Launch canceled!”

Turning the debug on, I notice the problem seems to be with the keystore classes.

From http://naveenbalani.com/index.php/2011/01/getting-started-with-android-creating-android-application/

Published at DZone with permission of Naveen Balani, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Alex(JAlexoid) ... replied on Tue, 2011/02/15 - 6:12am

Sorry. The default setup created by New Android Project wizard is better than what you provided.

And you failed to note 3 important parts of the Android application:

  • Application Manifest 
  • Activity
  • XML based layouts

Good luck next time.

 

PS: In your previous post the architecture picture is inacurate at best. You could have used the official immage at http://d.android.com/images/system-architecture.jpg

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.