What Readers Are Saying About Hello,
Android
Learn to develop Android apps with this complete yet gentle introduc-
tion to the Android platform. Out of all the books on Android, Hello,
Android has the best flow and coverage for developers new to this plat-
form. You’ll be writing Android apps in no time!
Marko Gargenta
CEO,
, Marakana.com
The third edition of Hello, Android gets you on the fast track of
Android application development, from the basic concepts to pub-
lishing to the Android Market. Ed shows his vast experience on the
subject and even covers hard-to-find topics such as multi-touch and
OpenGL. This is a must-read for everyone starting on the fascinating
journey of Android development.
Diego Torres Milano
Andr
oid expert and blogger,
I thoroughly enjoyed the Hello, Android book, and it helped me get on
the right track to releasing my first two apps to the Market.
Nathan Rapp
Founder
, , KMBurrito Designs
More than a greeting, Hello, Android welcomes both beginners and
pros to Android development.
Michael Martin PMP
Founder
, , GoogleAndBlog and Mobile Martin
From Library of Wow! eBook
Hello, Android
Introducing Google’s
Mobile Development Platform, 3rd Edition
Ed Burnette
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
From Library of Wow! eBook
Many of the designations used by manufacturers and sellers to distinguish their prod-
uc
ts 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 in initial capital letters 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 o m work created and shared by Google and
used according to terms described in the Creative Commons 2.5 Attribution License. See
http://code.google.com/policies.html#restr ictio ns for details.
Gestur
e icons in Chapter 11 courtesy of GestureWorks (www.gestureworks.com).
Every precaution was taken in the preparation of this book. However, 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 software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragprog.com.
Th
e team that produced this book includes:
Editor: Susannah Davidson Pfalzer
Indexing: Seth Maislin
Copy edit: Kim Wimpsett
Layout: Steve Peter
Production: Janet Furlow
Customer support: Ellie Callahan
International: Juliet Benda
Copyright
©
2010 Pragmatic Programmers, LLC.
All rights reserved.
No part of t his publication may be reproduced, stored in a retrieval 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-56-5
ISBN-13: 978-1-934356-56-2
Printed on acid-free paper.
P1.0 printing, July 2010
Version: 2010-7-16
From Library of Wow! eBook
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 in the Third Edition? . . . . . . . . . . . . . . . . . 12
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . . . . 14
I Introducing Android 16
1 Quick Start 17
1.1 Installing the Tools . . . . . . . . . . . . . . . . . . . . . 17
1.2 Creating Your First Program . . . . . . . . . . . . . . . . 23
1.3 Running on the Emulator . . . . . . . . . . . . . . . . . 23
1.4 Running on a Real Phone . . . . . . . . . . . . . . . . . 28
1.5 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 29
2 Key Concepts 30
2.1 The Big Picture . . . . . . . . . . . . . . . . . . . . . . . 30
2.2 It’s Alive! . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.3 Building Blocks . . . . . . . . . . . . . . . . . . . . . . . 39
2.4 Using Resources . . . . . . . . . . . . . . . . . . . . . . 40
2.5 Safe and Secure . . . . . . . . . . . . . . . . . . . . . . . 40
2.6 Fast-Forward >> . . . . . . . . . . . . . . . . . . . . . . . 41
From Library of Wow! eBook