What readers are saying about Hello, Android
This is a most excellent book: very well written, easy to read,
and fun.
In addition, any of Android’s quirks are explained along with just the
right amount of detail to ensure quality programming principles are
followed.
Anthony Stevens
Founder and CTO, PocketJourney and Top 20 Winner of
Google Android Competition
Ed Burnette covers an impressive amount of ground in a nicely com-
pact book while retaining the popular Pragmatic style. For the mate-
rial on 2D and 3D graphics alone, this is worthy of a spot in any
Android developer’s library.
Mark Murphy
Founder, CommonsWare
I remember when I first started to work with Android; it was like a
huge maze. With this book, the introduction would have been much
less painful. I am convinced that by reading this book new Android
programmers will have an easier start.
Gabor Paller
Senior Software Archi tect, OnRelay, Ltd.
Hello, Android
Intr oducing Google’s
Mobile Development Platform, 2nd Edition
Ed Burnette
The Pragmatic Bookshelf
Many of the designations used by manufacturers and sellers to distinguish their prod-
ucts are claimed as trademarks. Where those designations appear in this book, and The
Pragmatic Programmers, LLC was aware of a trademark claim, the designations have
been printed i n initial capital le tters or in all capitals. The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g
device are trademarks of The Pragmatic Programmers, LLC.
Portions of the book’s cover are reproduced fr om work created
and shared by Google and
used according to terms described in t he Creative Commons 2.5 Attribution License. See
http://code.google.com/polic ies.html#restrictions for details.
Every precaution was taken in the preparation of this book. Ho
wever, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better s oftware and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragprog.com
Copyright
©
2
009 Ed Burnette.
All rights reserved.
No part of this publication may be reproduced, stored in a re trie val system, or transmit-
ted, in any form, or by any means, electronic, mechanical, photocopying, recording, or
otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-49-2
ISBN-13: 978-1-934356-49-4
Printed on acid-free paper.
P1.0 printing, October 2009
Version: 2009-10-6
Contents
Acknowledgments 9
Preface 10
What Makes Android Special? . . . . . . . . . . . . . . . . . . 10
Who Should Read This Book? . . . . . . . . . . . . . . . . . . . 11
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . 12
What’s New for Cupcake? . . . . . . . . . . . . . . . . . . . . . 12
What’s New for Donut? . . . . . . . . . . . . . . . . . . . . . . . 13
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . . . . 14
I Introducing Android 15
1 Quick Start 16
1.1 Installing the Tools . . . . . . . . . . . . . . . . . . . . . 16
1.2 Creati ng Your First Program . . . . . . . . . . . . . . . . 20
1.3 Running on the Emulator . . . . . . . . . . . . . . . . . 20
1.4 Running on a Real Phone . . . . . . . . . . . . . . . . . 23
1.5 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 24
2 Key Concepts 27
2.1 The Big Picture . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 It’s Alive! . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.3 Building Blocks . . . . . . . . . . . . . . . . . . . . . . . 36
2.4 Using Resources . . . . . . . . . . . . . . . . . . . . . . 37
2.5 Safe and Secure . . . . . . . . . . . . . . . . . . . . . . . 38
2.6 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 39