ebook img

O'Reilly - Android Application Development - skityaev.ru PDF

336 Pages·2009·4.33 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview O'Reilly - Android Application Development - skityaev.ru

Android Application Development Rick Rogers, John Lombardo, Zigurd Mednieks, and Blake Meike Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo Android Application Development by Rick Rogers, John Lombardo, Zigurd Mednieks, and Blake Meike Copyright © 2009 Rick Rogers, John Lombardo, Zigurd Mednieks, and Blake Meike. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://mysafaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Andy Oram Indexer: Joe Wizda Production Editor: Sumita Mukherji Cover Designer: Karen Montgomery Copyeditor: Genevieve d’Entremont Interior Designer: David Futato Proofreader: Sada Preisch Illustrator: Robert Romano Printing History: May 2009: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Android Application Development, the image of an Eastern quoll and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. TM This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-52147-9 [M] 1241533714 Table of Contents Preface ..................................................................... ix Part I. Development Kit Walk-Through 1. Getting to Know Android ................................................. 3 Why Android? 3 The Open Handset Alliance 4 The Android Execution Environment 5 Components of an Android Application 6 Android Activity Lifecycle 8 Android Service Lifecycle 10 How This Book Fits Together 10 2. Setting Up Your Android Development Environment ......................... 13 Setting Up Your Development Environment 13 Creating an Android Development Environment 14 Hello, Android 18 Where We’re Going 18 Starting a New Android Application: HelloWorld 18 Writing HelloWorld 22 Running HelloWorld 24 3. Using the Android Development Environment for Real Applications ............ 27 MicroJobs: This Book’s Main Sample Application 27 Android and Social Networking 27 Downloading the MJAndroid Code 30 A Brief Tour of the MJAndroid Code 30 The Project Root Folder (MJAndroid) 30 The Source Folder (src) 31 The Resource Folder (res) 32 First Steps: Building and Running the MicroJobs Application 33 iii A Very Short Tour of the Android SDK/Eclipse IDE 33 Loading and Starting the Application 35 Digging a Little Deeper: What Can Go Wrong? 36 Running an Application on the T-Mobile Phone 39 Summary 41 4. Under the Covers: Startup Code and Resources in the MJAndroid Application .... 43 Initialization Parameters in AndroidManifest.xml 44 Initialization in MicroJobs.java 46 More Initialization of MicroJobs.java 52 Summary 56 5. Debugging Android Applications ......................................... 57 The Tools 57 Eclipse Java Editor 58 Java Errors 58 The Debugger 64 Logcat 67 Android Debug Bridge (adb) 71 DDMS: Dalvik Debug Monitor Service 74 Traceview 75 Summary 80 6. The ApiDemos Application ............................................... 81 Application Setup in the Manifest File 81 Finding the Source to an Interesting Example 83 Custom Title Demo 83 Linkify Demo 84 Adding Your Own Examples to ApiDemos 84 7. Signing and Publishing Your Application ................................... 87 Test Your Application 88 Attach an End User License Agreement If Desired 89 Create and Attach an Icon and Label 89 Clean Up for Release 90 Version Your Application 90 Obtaining a Signing Certificate and API Key 90 Getting a Signing Certificate for an Application You Are Going to Ship 91 Getting a Signing Certificate While Debugging 93 Signing Your Application 95 Retesting Your Application 96 Publishing on Android Market 96 Signing Up As an Android Developer 96 iv | Table of Contents Uploading Your Application 96 Part II. Programming Topics 8. Persistent Data Storage: SQLite Databases and Content Providers ............. 101 Databases 101 Basic Structure of the MicroJobsDatabase Class 102 Reading Data from the Database 107 Modifying the Database 110 Content Providers 114 Introducing NotePad 116 Content Providers 118 Consuming a Content Provider 129 9. Location and Mapping ................................................. 137 Location-Based Services 137 Mapping 139 The Google Maps Activity 139 The MapView and MapActivity 140 Working with MapViews 140 MapView and MyLocationOverlay Initialization 141 Pausing and Resuming a MapActivity 144 Controlling the Map with Menu Buttons 145 Controlling the Map with the KeyPad 147 Location Without Maps 148 The Manifest and Layout Files 148 Connecting to a Location Provider and Getting Location Updates 149 Updating the Emulated Location 152 10. Building a View ....................................................... 157 Android GUI Architecture 157 The Model 157 The View 158 The Controller 159 Putting It Together 159 Assembling a Graphical Interface 161 Wiring Up the Controller 166 Listening to the Model 168 Listening for Touch Events 173 Listening for Key Events 176 Alternative Ways to Handle Events 177 Advanced Wiring: Focus and Threading 179 Table of Contents | v The Menu 183 11. A Widget Bestiary ..................................................... 187 Android Views 188 TextView and EditText 188 Button and ImageButton 191 Adapters and AdapterViews 192 CheckBoxes, RadioButtons, and Spinners 193 ViewGroups 198 Gallery and GridView 198 ListView and ListActivity 202 ScrollView 204 TabHost 205 Layouts 208 Frame Layout 209 LinearLayout 209 TableLayout 213 AbsoluteLayout 215 RelativeLayout 216 12. Drawing 2D and 3D Graphics ............................................ 221 Rolling Your Own Widgets 221 Layout 222 Canvas Drawing 226 Drawables 237 Bitmaps 242 Bling 243 Shadows, Gradients, and Filters 246 Animation 247 OpenGL Graphics 252 13. Inter-Process Communication ........................................... 257 Intents: Simple, Low-Overhead IPC 258 Intent Objects Used in Inter-Process Communication 258 Activity Objects and Navigating the User Interface Hierarchy 259 Example: An Intent to Pick How We Say “Hello World” 259 Getting a Result via Inter-Process Communication 262 Remote Methods and AIDL 265 Android Interface Definition Language 266 Classes Underlying AIDL-Generated Interfaces 270 Publishing an Interface 273 Android IPC Compared with Java Native Interface (JNI) 274 What Binder Doesn’t Do 275 vi | Table of Contents Binder and Linux 275 14. Simple Phone Calls .................................................... 277 Quick and Easy Phone Calls 277 Creating an Example Application to Run the call Method 278 Embedding the Code Snippet in a Simple Application 279 Exploring the Phone Code Through the Debugger 280 Creating an Instance of an Intent 282 Adding Data to an Instance of an Intent 283 Initiating a Phone Call 284 Exception Handling 284 Android Application-Level Modularity and Telephony 285 15. Telephony State Information and Android Telephony Classes ................ 287 Operations Offered by the android.telephony Package 287 Package Summary 288 Limitations on What Applications Can Do with the Phone 288 Example: Determining the State of a Call 289 Android Telephony Internals 291 Inter-Process Communication and AIDL in the android.internal.telephony Package 291 The android.internal.telephony Package 292 The android.internal.telephony.gsm Package 295 Exploring Android Telephony Internals 299 Android and VoIP 302 Appendix: Wireless Protocols ................................................. 305 Index ..................................................................... 309 Table of Contents | vii

Description:
Using the Android Development Environment for Real Applications Add the full path of the tools directory to the end of the existing Path variable
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.