WhatReadersAreSayingAboutHello,AndroidLearntodevelopAndroidappswiththiscompleteyetgentleintroduc-tiontotheAndroidplatform.OutofallthebooksonAndroid,Hello,Androidhasthebestflowandcoveragefordevelopersnewtothisplat-form.You’llbewritingAndroidappsinnotime!MarkoGargentaCEO,,Marakana.comThethirdeditionofHello,AndroidgetsyouonthefasttrackofAndroidapplicationdevelopment,fromthebasicconceptstopub-lishingtotheAndroidMarket.Edshowshisvastexperienceonthesubjectandevencovershard-to-findtopicssuchasmulti-touchandOpenGL.Thisisamust-readforeveryonestartingonthefascinatingjourneyofAndroiddevelopment.DiegoTorresMilanoAndroidexpertandblogger,IthoroughlyenjoyedtheHello,Androidbook,andithelpedmegetontherighttracktoreleasingmyfirsttwoappstotheMarket.NathanRappFounder,,KMBurritoDesignsMorethanagreeting,Hello,AndroidwelcomesbothbeginnersandprostoAndroiddevelopment.MichaelMartinPMPFounder,,GoogleAndBlogandMobileMartinFromLibraryofWow!eBookHello,AndroidIntroducingGoogle’sMobileDevelopmentPlatform,3rdEditionEdBurnetteThePragmaticBookshelfRaleigh,NorthCarolinaDallas,TexasFromLibraryofWow!eBookManyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirprod-uctsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andThePragmaticProgrammers,LLCwasawareofatrademarkclaim,thedesignationshavebeenprintedininitialcapitallettersorinallcapitals.ThePragmaticStarterKit,ThePragmaticProgrammer,PragmaticProgramming,PragmaticBookshelfandthelinkinggdevicearetrademarksofThePragmaticProgrammers,LLC.Portionsofthebook’scoverarereproducedfromworkcreatedandsharedbyGoogleandusedaccordingtotermsdescribedintheCreativeCommons2.5AttributionLicense.See().Everyprecautionwastakeninthepreparationofthisbook.However,thepublisherassumesnoresponsibilityforerrorsoromissions,orfordamagesthatmayresultfromtheuseofinformation(includingprogramlistings)containedherein.OurPragmaticcourses,workshops,andotherproductscanhelpyouandyourteamcreatebettersoftwareandhavemorefun.Formoreinformation,aswellasthelatestPragmatictitles,pleasevisitusat:SusannahDavidsonPfalzerIndexing:SethMaislinCopyedit:KimWimpsettLayout:StevePeterProduction:JanetFurlowCustomersupport:EllieCallahanInternational:JulietBendaCopyright©2010PragmaticProgrammers,LLC.Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmit-ted,inanyform,orbyanymeans,electronic,mechanical,photocopying,recording,orotherwise,withoutthepriorconsentofthepublisher.PrintedintheUnitedStatesofAmerica.ISBN-10:1-934356-56-5ISBN-13:978-1-934356-56-2Printedonacid-freepaper.P1.0printing,July2010Version:2010-7-16FromLibraryofWow!eBookContentsAcknowledgments9Preface10WhatMakesAndroidSpecial?..................10WhoShouldReadThisBook?...................11What’sinThisBook?........................12What’sNewintheThirdEdition?.................12OnlineResources..........................14Fast-Forward..........................14IIntroducingAndroid161QuickStart171.1InstallingtheTools.....................171.2CreatingYourFirstProgram................231.3RunningontheEmulator.................231.4RunningonaRealPhone.................281.5Fast-Forward.......................292KeyConcepts302.1TheBigPicture.......................302.2It’sAlive!...........................352.3BuildingBlocks.......................392.4UsingResources......................402.5SafeandSecure.......................402.6Fast-Forward.......................41FromLibraryofWow!eBookCONTENTS6IIAndroidBasics423DesigningtheUserInterface433.1IntroducingtheSudokuExample.............433.2DesigningbyDeclaration.................443.3CreatingtheOpeningScreen...............453.4UsingAlternateResources.................553.5ImplementinganAboutBox................573.6ApplyingaTheme......................613.7AddingaMenu.......................643.8AddingSettings.......................653.9StartingaNewGame....................663.10Debugging..........................693.11ExitingtheGame......................713.12Fast-Forward.......................714Exploring2DGraphics734.1LearningtheBasics.....................734.2AddingGraphicstoSudoku................784.3HandlingInput.......................874.4TheRestoftheStory....................934.5MakingMoreImprovements................1034.6Fast-Forward.......................1035Multimedia1055.1PlayingAudio........................1055.2PlayingVideo........................1125.3AddingSoundstoSudoku.................1155.4Fast-Forward.......................1196StoringLocalData1206.1AddingOptionstoSudoku.................1206.2ContinuinganOldGame.................1226.3RememberingtheCurrentPosition............1246.4AccessingtheInternalFileSystem............1266.5AccessingSDCards....................1276.6Fast-Forward.......................128Reporterratumthiscopyis(P1.0printing,July2010)FromLibraryofWow!eBookCONTENTS7IIIBe