Book Giveaway & Exclusive Chapter Excerpt: Hello Android

DZone 's Guide to

Book Giveaway & Exclusive Chapter Excerpt: Hello Android

· Mobile Zone ·
Free Resource

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. 


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}