Android Create AVD

The second part of this series covers creating our first Android Virtual Device or AVD. The Android Virtual Device (AVD) is basically a configuration for the Android SDK’s emulator that lets you define the hardware and software characteristics of an actual Android advice that you can then test your code on. Whilst not being as good as running your app on real hardware, testing it on an AVD is the next best thing!

You can either watch the Android Create AVD video above or follow the steps below, it’s dead easy!

Start The AVD Manager
Start The AVD Manager

First we need to start the AVD Manager by going to Window -> AVD Manager

Create A New AVD
Create A New AVD

Then click on New to bring up the AVD Configuration Dialog.

Choose AVD Settings
Choose AVD Settings

Enter an appropriate name, select your API target, the size of the SD card and skin/resolution you want to use then click Create AVD.

AVD Will Appear In The List
AVD Will Appear In The List

The AVD creation will take about 1 minute to run, but then the new AVD will appear in your list of available AVDs. It’s possible to make many different AVDs to test your application on many different screen sizes and hardware profiles!

Learning Android

If you’re new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. This gentle introduction shows you how to use Android’s basic building blocks to develop user interfaces, store data, and more. You’ll build an example application throughout the course of book, adding new features with each chapter. You’ll also build your own toolbox of code patterns that will help you program any type of Android application with ease.

Install Android Eclipse

Hi guys, when telling a story it’s always best to start at the beginning, so the first thing to do on my journey is talk about how are we going to install Android Eclipse. My workstation is a MacBook but the process is the same on both Windows and Linux. I’ve put together a short video of the entire thing, from downloading Eclipse and the Android SDK to installing Eclipse, the ADT (Android Development Tools) plugin and then configuring ADT to use the Android SDK!

The steps are really simple.

  1. Download and install the Eclipse IDE for Java Developers from http://www.eclipse.org/downloads/
  2. Download and extract the Android SDK from http://developer.android.com/sdk/index.html
  3. Install the ADT plugin in Eclipse

After following these 3 easy steps to install Android Eclipse you should be ready to go!

Learning Android

If you’re new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. This gentle introduction shows you how to use Android’s basic building blocks to develop user interfaces, store data, and more. You’ll build an example application throughout the course of book, adding new features with each chapter. You’ll also build your own toolbox of code patterns that will help you program any type of Android application with ease.

Tomcat HelloWorld Servlet with Eclipse

I’m really trying to get in to this whole Java web development frame of mind, as it’s a bit of fun, a bit of a giggle, and it’s massive in this area of the world! So obviously my first port of call was dusting off Eclipse and kicking out a HelloWorld style Java servlet!

I grabbed a copy of O’Rielly’s Java Servlet Programming to get started and found it really invaluable, and definitely recommend this book to anyone starting out in Java servlet programming.

Eclipse on Ubuntu, even Intrepid is well old, so rather than work with the out of date supplied package, I found it best to download the latest version direct from the site. Also the easiest way to hook Tomcat in to Eclipse is also to download that from the site.

Get the latest Eclipse IDE for Java EE Developers and Tomcat 6

Extract them both to somewhere reasonable, I like ~/local :


idimmu@boosh:~/local$ ls -al
total 173212
drwxr-xr-x 4 idimmu idimmu 4096 2009-03-11 15:01 .
drwxr-xr-x 63 idimmu idimmu 4096 2009-03-11 15:01 ..
drwxr-xr-x 9 idimmu idimmu 4096 2009-03-11 15:01 apache-tomcat-6.0.18
-rw-r--r-- 1 idimmu idimmu 6142197 2009-03-11 11:27 apache-tomcat-6.0.18.tar.gz
drwxr-sr-x 9 idimmu idimmu 4096 2009-02-23 19:36 eclipse
-rw-r--r-- 1 idimmu idimmu 171022452 2009-03-11 10:57 eclipse-jee-ganymede-SR2-linux-gtk.tar.gz

Start Eclipse! The first thing that Eclipse will do is ask you to create a new Workspace. Your home directory isn’t a bad choice to put this!

Tomcat HelloWorld Servlet with Eclipse

Go to New->Project

Tomcat HelloWorld Servlet with Eclipse

Select ‘Dynamic Web Project’

Set ‘Project Name’ to ‘helloworld’

Create a ‘New’ ‘Target Runtime’

Select ‘Apache Tomcat v6.0’

Select the Tomcat Installation Directory you extracted Tomcat to earlier.

Then click ‘Finish’ to create the project.
Go to File->New->Servlet

Enter ‘HelloWorld’ as the ‘Class name’
Click ‘Finish’

A new ‘HelloWorld.java’ file will be created with most of the work done for you!

Tomcat HelloWorld Servlet with Eclipse

Look at all the shiny code the IDE has already written for you!

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class HelloWorld
*/
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public HelloWorld() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

This code does nothing on it’s own, well, it will generate a completely empty web page if you build it and deploy it to Tomcat, not very exciting .. so ..

Import the following new class:


import java.io.PrintWriter;

Insert the following code in to the doGet function stub:


response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("");
pw.println("");
pw.println("");
pw.println("

Hello World

");
pw.println("");

The complete source code for the class will now look like this:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class HelloWorld
*/
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorld() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("");
pw.println("");
pw.println("");
pw.println("

Hello World

");
pw.println("");
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}

‘Save All’ using Shift+Ctrl+S or the File menu.
Go to the ‘Run’ menu and select ‘Run’ or press Ctrl+F11 to build the servlet, deploy it to Tomcat and run it!

Tomcat HelloWorld Servlet with Eclipse

Make sure ‘Tomcat v6.0 Server’ is selected and click ‘Always use this server when running this project’ then click ‘Finish’

Tada, Hello World! You might have to run it a few times to get Tomcat to sort itself out, as it’s a bit wonky, but the very mundane site should now be available on http://localhost:8080/helloworld/HelloWorld!!

Eclipse

If you really want to be a rock and roll Java super star and learn how to use Eclipse and Tomcat properly, I thoroughly suggest you get a copy of O’Reilly’s Eclipse book and learn how to use it properly.