Sams Teach Yourself Android Application Development in 24 Hours / Lauren Darcey, Shane Kitty Wilson Conder
Total Page:16
File Type:pdf, Size:1020Kb
ptg Lauren Darcey Shane Conder SamsTeach Yourself Android™ Application Development ptg in Hours24 800 East 96th Street, Indianapolis, Indiana 46240 USA Sams Teach Yourself Android™ Application Development in 24 Hours Editor-in-Chief Mark Taub Copyright © 2010 Lauren Darcey and Shane Conder All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or Acquisitions Editor transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without Trina MacDonald written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of Development this book, the publisher and author assume no responsibility for errors or omissions. Nor is any Editor liability assumed for damages resulting from the use of the information contained herein. Michael Thurston Visible Earth images owned by NASA, http://visibleearth.nasa.gov/. Managing Editor ISBN-13: 978-0-321-67335-0 Kristy Hart ISBN-10: 0-321-67335-2 Library of Congress Cataloging-in-Publication Data Project Editor Betsy Harris Darcey, Lauren, 1977- Copy Editor Sams teach yourself Android application development in 24 hours / Lauren Darcey, Shane Kitty Wilson Conder. p. cm. — (Sams teach yourself in 24 Hours) Indexer Includes index. Erika Millen ISBN 978-0-321-67335-0 (pbk.) Proofreader 1. Application software—Development. 2. Android (Electronic resource) 3. Mobile computing. Sheri Cain I. Conder, Shane, 1975- II. Title. QA76.76.A65D26 2010 Technical Editor 005.1—dc22 Jonathan Jackson 2010011663 Publishing Printed in the United States of America Coordinator First Printing June 2010 Olivia Basegio Trademarks Book Designer ptg All terms mentioned in this book that are known to be trademarks or service marks have been Gary Adair appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service Senior Compositor mark. Gloria Schurick Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the programs accompanying it. Bulk Sales Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk pur- chases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales [email protected] Contents at a Glance Introduction.............................................................................................................................................. 1 Part I: Android Fundamentals HOUR 1 Getting Started with Android . ................................................................................................... 7 2 Mastering the Android Development Tools . ............................................................... 27 3 Building Android Applications . ............................................................................................ 43 4 Managing Application Resources ........................................................................................ 59 5 Configuring the Android Manifest File. .......................................................................... 77 6 Designing an Application Framework. ............................................................................ 95 Part II: Building an Application Framework HOUR 7 Implementing an Animated Splash Screen ............................................................. 113 ptg 8 Implementing the Main Menu Screen . ........................................................................ 127 9 Developing the Help and Scores Screens . ................................................................... 143 10 Building Forms to Collect User Input. ............................................................................ 161 11 Using Dialogs to Collect User Input ............................................................................... 181 12 Adding Application Logic . ................................................................................................... 197 Part III: Enhancing Your Application with Powerful Android Features HOUR 13 Working with Images and the Camera ........................................................................ 217 14 Adding Support for Location-Based Services . .......................................................... 233 15 Adding Network Support . ....................................................................................................... 255 16 Adding More Network Support .......................................................................................... 277 17 Adding Social Features . ............................................................................................................ 291 18 Creating a Home Screen App Widget . .......................................................................... 305 Part IV: Adding Polish to Your Android Application HOUR 19 Internationalizing Your Application . ............................................................................ 321 20 Developing for Different Devices . ..................................................................................... 333 21 Diving Deeper into Android ................................................................................................. 347 22 Testing Android Applications . .............................................................................................. 367 iv Teach Yourself Android Application Development in 24 Hours Part V: Publishing Your Application HOUR 23 Getting Ready to Publish . ....................................................................................................... 383 24 Publishing on the Android Market ................................................................................. 395 Part VI: Appendixes A Configuring Your Android Development Environment .................................. 409 B Eclipse IDE Tips and Tricks . ................................................................................................... 415 C Supplementary Materials. ....................................................................................................... 423 ptg v Table of Contents Introduction 1 Part I: Android Fundamentals HOUR 1: Getting Started with Android 7 Introducing Android . ......................................................................................................................................... 7 Familiarizing Yourself with Eclipse.......................................................................................................... 9 Running and Debugging Applications . .......................................................................................... 17 Summary ................................................................................................................................................................ 23 Q&A. ............................................................................................................................................................................. 23 Workshop ................................................................................................................................................................ 24 HOUR 2: Mastering the Android Development Tools ptg 27 Using the Android Documentation . .............................................................................................. 27 Debugging Applications with DDMS . .......................................................................................... 29 Working with the Android Emulator . .............................................................................................. 35 Using Other Android Tools . ....................................................................................................................... 38 Summary ................................................................................................................................................................ 39 Q&A. ............................................................................................................................................................................. 40 Workshop ................................................................................................................................................................ 40 HOUR 3: Building Android Applications 43 Designing a Typical Android Application . ................................................................................... 43 Using the Application Context . ............................................................................................................ 46 Working with Activities . .............................................................................................................................. 47 Working with Intents ....................................................................................................................................... 51 Working with Dialogs . .................................................................................................................................