Programming Languages/Java ™ g Easier! Here’s just what you need Making Everythin to start developing feature-rich, amazing Android apps ™ Android™ Application Development id Open the book and find: Even if you’ve never written a mobile application, this book has the know-how you need to turn your great ideas into cool apps for the Android platform. With millions of smartphone users and a cornucopia of carriers, Android is a great place to ply the app development trade. This book shows you • Cool ways to use the accelerometer in your app • How to turn mobile limitations into opportunities n d ro Acation Development Appli • Tips on installing and setting up from the ground up how to set up your environment and the tools create an app. Read on to become an Android developer extraordinaire! • Step-by-step coding directions • Ways to make your apps more • Welcome to Android — learn what makes a great Android app, marketable how to use the SDK, ways to work with mobile screens, and how the development process works • How to create really useful menus • Make users happy — find out how to design an interface that • Advice on app pricing mobile users will love • Ten great sample apps and SDKs, • Learn the code — work with the activity lifecycle and Android including code framework classes, use the Eclipse debugger, and create a home screen widget for your app • Beyond the basics — take your skills up a notch with apps that involve SQLite databases and multiple screens • Price and publish — pick the right price for your app and get it into the Android Market Learn to: • Create apps for hot smartphones like Go to Dummies.com® Droid™ X, Galaxy S, and MyTouch® for videos, step-by-step examples, Visit the companion Web site at www.com/go/ how-to articles, or to shop! • Download the SDK and get Eclipse androidappdevfd for source code, updates, and other up and running examples to help you in the development process • Code Android applications • Submit your apps to the Android Market $29.99 UK Donn Felker is an independent consultant specializing in Android and ISBN 978-0-470-77018-4.
He has been a technical architect, software developer, and programmer analyst for more than a decade, with experience that covers desktop, Web, and mobile development. Donn Felker Felker Independent software development consultant Get More and Do More at Dummies.com® Start with FREE Cheat Sheets Cheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff! To access the Cheat Sheet created specifically for this book, go to www.com/cheatsheet/androidapplicationdevelopment Mobile Apps Get Smart at Dummies.com makes your life easier with 1,000s of answers on everything from removing wallpaper to using the latest version of Windows. Check out our • Videos • Illustrated Articles • Step-by-Step Instructions There’s a Dummies App for This and That Plus, each month you can win valuable prizes by entering our Dummies. * With more than 200 million books in print and over 1,600 unique Want a weekly dose of Dummies? Sign up for Newsletters on titles, Dummies is a global leader in how-to information.
Now • Digital Photography you can get the same great Dummies information in an App. With • Microsoft Windows & Office topics such as Wine, Spanish, Digital Photography, Certification, • Personal Finance & Investing and more, you’ll have instant access to the topics you need to • Health & Wellness know in a format you can trust. • Computing, iPods & Cell Phones • eBay To get information on all our Dummies apps, visit the following: • Internet www.com/go/mobile from your computer. • Food, Home & Garden www.com/go/iphone/apps from your phone.
Find out “HOW” at Dummies.com *Sweepstakes not currently available in all countries; visit Dummies.com for official rules. Android ™ Application Development FOR DUMmIES ‰ Android ™ Application Development FOR DUMmIES ‰ by Donn Felker with Joshua Dobbs AndroidTM Application Development For Dummies ® Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.com Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada 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, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http:// www.com/go/permissions.
Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/ or its affiliates in the United States and other countries, and may not be used without written permission. Android is a trademark of Google, Inc. All other trademarks are the property of their respective owners.
Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH- OUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION.
THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZA- TION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE.
FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U. at 877-762-2974, outside the U. at 317-572-3993, or fax 317-572-4002.
For technical support, please visit www. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2010939962 ISBN: 978-0-470-77018-4 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 About the Authors Donn Felker is a recognized leader in the development and consultation of state-of-the-art, cutting-edge software in the mobile and Web fields.
He is an independent consultant with over 10 years of professional experience in various markets that include entertainment, health, retail, insurance, finan- cial, and real estate. He is a mobile junkie, serial entrepreneur, and creative innovator in all things mobile and Web. He is the founder of Agilevent, an innovative creative development firm that has done work for small startups as well as Fortune 500 companies. He is a Microsoft ASP Insider, an MCTS for .5 Web Applications, and a certified ScrumMaster.
He’s a national speaker on topics that include Android, .NET, and software architecture. He is the author of the TekPub.com Introduction to Android video series. He is a writer, presenter, and consultant on various topics rang- ing from architecture to development in general, agile practices, and patterns and practices. Follow Donn on Twitter (@donnfelker) or read his blog here: http://blog.
Joshua Dobbs is a senior lead Web application developer for a large elec- tronics manufacturer in Southern California. He has more than ten years’ experience in Web and desktop application development. Josh was an early adopter of the Android platform and creates Android apps in his spare time. His apps have been downloaded more than 6 million times, and he was selected by Google as top Android developer for its Device Seeding Program.
His Web site is www. Dedication To my dogs, Lulu and Macho, and my cat, Vito: Thanks for keeping me company in the cold basement while I cranked out page after page in the wee hours of the morning while everyone else was asleep. Writing is a lonely gig, and your company helped the time pass much easier (and kept my feet and lap warm too). To my dearest daughter, Sophia, who made even the toughest days brighter through her contagious, infectious laughter and antics.
Most of all, to my gorgeous wife, Ginamarie, who has always been very sup- portive of all my crazy, harebrained ideas over the years. I would not have gotten where I am in my life if it were not for your support. Author’s Acknowledgments Thanks to coauthor Joshua Dobbs for writing the couple of chapters that I needed help with. May we both have many more successful books in the future! Thanks to Wiley Acquisitions Editor Kyle Looper for giving me a shot at writ- ing this book.
I really appreciate the help, support, and insight into everything publishing-related. You’ve been a life saver on this project. Project Editor Kathy Simpson pushed me beyond what I thought would be possible in terms of the organization of the content and readability. Thank you for being a diligent editor.
Copy Editor John Edwards helped find some of my most subtle mistakes, which allowed me to polish the book content even more. Technical Editor Andre Taddeini is one of the few technical individuals I trust wholeheartedly. I’m glad you were my second pair of eyes on this project. Your sanity check of the technical accuracy of the book was outstanding.
Finally, thank you to my friend John Benda for contributing by being supportive of me and my family during this process. It’s been a long road. Now it’s your turn to write a book! Publisher’s Acknowledgments We’re proud of this book; please send us your comments at http://dummies. For other comments, please contact our Customer Care Department within the U.
at 877-762-2974, outside the U. at 317-572-3993, or fax 317-572-4002. Some of the people who helped bring this book to market include the following: Acquisitions and Editorial Composition Services Project Editor: Kathy Simpson Project Coordinator: Sheree Montgomery Acquisitions Editor: Kyle Looper Layout and Graphics: Nikki Gately, Copy Editor: John Edwards Laura Westhuis Technical Editor: Andre Taddeini Proofreaders: Laura Bowman, Rebecca Denoncour Editorial Manager: Jodi Jensen Indexer: BIM Indexing & Proofreading Services Editorial Assistant: Amanda Graham Sr. Editorial Assistant: Cherie Case Cartoons: Rich Tennant (www.com) Publishing and Editorial for Technology Dummies Richard Swadley, Vice President and Executive Group Publisher Andy Cummings, Vice President and Publisher Mary Bednarek, Executive Acquisitions Director Mary C.
Corder, Editorial Director Publishing for Consumer Dummies Diane Graves Steele, Vice President and Publisher Composition Services Gerry Fahey, Vice President of Production Services Debbie Stailey, Director of Composition Services Contents at a Glance Introduction. 1 Part I: The Nuts and Bolts of Android. 7 Chapter 1: Developing Spectacular Android Applications. 9 Chapter 2: Prepping Your Development Headquarters.
25 Part II: Building and Publishing Your First Android Application. 53 Chapter 3: Your First Android Project. 55 Chapter 4: Designing the User Interface. 93 Chapter 5: Coding Your Application.
117 Chapter 6: Understanding Android Resources. 155 Chapter 7: Turning Your Application into a Home-Screen Widget. 163 Chapter 8: Publishing Your App to the Android Market .