Book Giveaway & Exclusive Chapter Excerpt: Hello Android

DZone and Pragmatic Bookshelf have partnered to bring you an exclusive chapter from 'Hello Android' (by Ed Burnette). This excerpt shows you how to create your first Android program and how to actually run it on a real phone. 

Creating Your First Program

Android Development Tools (ADT) comes with a built-in example program, or template, that we’re going to use to create a simple “Hello, Android” program in just a few seconds. Get your stopwatch ready. Ready? Set? Go!

Select File > New > Project... to open the New Project dialog box. Then select Android > Android Project, and click Next.

Enter the following information:

Project name: HelloAndroid
Build Target: Android 1.5
Application name: Hello, Android
Package name: org.example.hello
Create Activity: Hello

When you’re done, it should look something like Figure 1.2, on the following page.

Click Finish. The Android plug-in will create the project and fill it in with some default files. Eclipse will build it and package it up so it will be ready to execute. If you get an error about missing source folders, select Project > Clean to fix it.

OK, that takes care of writing the program; now all that’s left is to try running it. First we’ll run it under the Android Emulator.

Running on the Emulator

To run your Android program, go to the Package Explorer window, right-click the HelloAndroid project, and select Run As > Android Application. If you’re following along in Eclipse you may see an error dialog like the one in Figure 1.3, on page 28. This indicates we haven’t told the Emulator what kind of phone to emulate.

Creating an AVD

To do this, you need to create an Android Virtual Device (AVD), using either Eclipse or the android avd command.6 It’s easier to use Eclipse, so select Yes in the AVD Error dialog to open the AVD Manager. You
can open the manager again later by selecting Window > Android AVD Manager.

Click here to download the entire excerpt.

 

The above excerpt was extracted from Hello Android, published in December 2008 by Pragmatic Bookshelf. It is being reproduced here by permission from Pragmatic Bookshelf. For more information or to purchase a paperback or PDF copy, visit the Hello Android homepage.

Copyright © 2008 Ed Burnette. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. 

AttachmentSize
HelloAndroid.pdf240.2 KB
bookcontest_android.png37.34 KB
0

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

Comments

timothy vance replied on Wed, 2009/08/05 - 11:12am

I've only have a little bit of experience using Android tech. I put together a few of the examples found at Google. I kinda like that the UI development has two entry points. I write a lot in Swing so i'm pretty used to having to build a UI in the code, but the ability to do it all in XML seems kinda neat; when I get time will probably be playing with that more. (On a related note, the Eclipse plugin is great!)

Brian West replied on Wed, 2009/08/05 - 12:26pm

I have just recently began starting to code for Android. I have completed many of the tutorials on the official Android Developer website as well as some tutorial sites. They have been great so far, for novices like me. I would like to look into a good book and this 'Hello, Android' book looks like it will fit the bill well. Appears to be in great detail, as well as tutorials for the Eclipse environment, which is great. Looking forward to expand my knowledge in writing applications for this platform, maybe even make some profit from it. :)

Stephen Robillard replied on Wed, 2009/08/05 - 4:12pm

I just recently started learning android programming. I think the thing that made this an easier decision (what to learn next) was the release of development tools for ubuntu and tols that let me run it on my desktop. These tools meant I could streamline the workflow and use the end product from not just my phone.

Vaibhav Mishra replied on Wed, 2009/08/05 - 11:26pm

Just completed the excerpt, it get me up and running, although I tried it several times in the past but command line and without IDE is not my cup of tea, and netbeans android plugin seems to be broken (I don't know it simply fails to start emulator), this chapter get me started , I never used eclipse and I am too lazy to hunt blogs and documentation for instructions, not only I have a working system running android with ADT , but I now had tried several programs in emulator, Thanks for such a nice book. but no Indian edition.

Mihai Campean replied on Thu, 2009/08/06 - 2:05am

I've started playing with Android last autumn and all I can say about the experience so far is that I like the platform very much, so much that I decided it would be an interesting idea to participate in the ADC2 contest. Until now I've only worked on an aplication conceived for learning purposes and which is available as open source on google code (here). Please note that it is still work in progress and development on it stagnates now as I am concentrating on the ADC2 application, so I think that a book about cupcake such as "Hello Android" would be of great assistance in this process since it is oriented toward the busy developer, and it would make a great reference while I progress in my work :).

Comment viewing options

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