HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
Android Wireless Application Development has earned a reputation as the most useful real-world guide to building robust, commercial-grade Android apps. Now, authors Lauren Darcey and Shane Conder have systematically revised and updated this guide for the latest Android SDK 4.0. To accommodate their extensive new coverage, they’ve split the book into two volumes. Volume I focuses on Android essentials, including setting up your development environment, understanding the application lifecycle, designing effective user interfaces, developing for diverse devices, and optimizing your mobile app development process--from design through publishing. Every chapter has been thoroughly updated for the newest APIs, tools, utilities, and hardware. All sample code has been overhauled and tested on leading devices from multiple companies, and many new examples have been added. Drawing on decades of in-the-trenches experience as professional mobile developers, Darcey and Conder provide valuable new best practices--including powerful techniques for constructing more portable apps. This new edition contains full chapters on Android manifest files, content providers, effective app design, and testing; an all-new chapter on tackling compatibility issues; coverage of today’s most valuable new Android tools and utilities; and even more exclusive tips and tricks. An indispensable resource for every Android development team member.
An Early Look at the Nexus Q from a Developer's Perspective
Programming Voice Commands for Android
The Basics of Android Programming
Author suggested site: http://androidbook.blogspot.com/
Android Wireless Application Development: Writing Your First Android Application
Download the sample pages (includes Chapter 3 and Index)
Introduction 1
Who Should Read This Book 1
Key Questions Answered in This Volume 2
How These Books Are Structured 2
An Overview of Changes in This Edition 4
Development Environment Used in This Book 5
Supplementary Materials Available 6
Where to Find More Information 6
Conventions Used in This Book 7
Contacting the Authors 8
PART I: AN OVERVIEW OF THE ANDROID PLATFORM
Chapter 1 Introducing Android 11
A Brief History of Mobile Software Development 11
Way Back When 11
“The Brick” 13
Wireless Application Protocol (WAP) 15
Proprietary Mobile Platforms 17
The Open Handset Alliance 19
Google Goes Wireless 19
Forming the Open Handset Alliance 19
Manufacturers: Designing Android Devices 20
Mobile Operators: Delivering the Android Experience 21
Apps Drive Device Sales: Developing Android Applications 22
Taking Advantage of All Android Has to Offer 22
The Android Marketplace: Where We’re at Now 22
Android Platform Differences 23
Android: A Next-Generation Platform 24
Free and Open Source 25
Familiar and Inexpensive Development Tools 25
Reasonable Learning Curve for Developers 26
Enabling Development of Powerful Applications 26
Rich, Secure Application Integration 26
No Costly Obstacles to Publication 27
A “Free Market” for Applications 27
A Growing Platform 28
The Android Platform 29
Android’s Underlying Architecture 29
Security and Permissions 31
Developing Android Applications 32
Summary 35
References and More Information 35
Chapter 2 Setting Up Your Android Development Environment 37
Configuring Your Development Environment 37
Configuring Your Operating System for Device Debugging 39
Configuring Your Android Hardware for Debugging 39
Upgrading the Android SDK 41
Problems with the Android Software Development Kit 41
Exploring the Android SDK 42
Understanding the Android SDK License Agreement 42
Reading the Android SDK Documentation 43
Exploring the Core Android Application Framework 43
Exploring the Core Android Tools 46
Exploring the Android Sample Applications 50
Summary 52
References and More Information 52
Chapter 3 Writing Your First Android Application 53
Testing Your Development Environment 53
Adding the Snake Project to Your Eclipse Workspace 54
Creating an Android Virtual Device (AVD) for Your Snake Project 56
Creating a Launch Configuration for Your Snake Project 58
Running the Snake Application in the Android Emulator 59
Building Your First Android Application 62
Creating and Configuring a New Android Project 62
Core Files and Directories of the Android Application 65
Creating an AVD for Your Project 65
Creating a Launch Configuration for Your Project 66
Running Your Android Application in the Emulator 67
Debugging Your Android Application in the Emulator 69
Adding Logging Support to Your Android Application 73
Adding Some Media Support to Your Application 74
Debugging Your Application on the Hardware 78
Summary 80
References and More Information 81
Chapter 4 Mastering the Android Development Tools 83
Using the Android Documentation 83
Leveraging the Android Emulator 85
Viewing Application Log Data with LogCat 86
Debugging Applications with DDMS 87
Using Android Debug Bridge (ADB) 87
Using the Resource Editors and UI Designer 88
Using the Android Hierarchy Viewer 91
Launching the Hierarchy Viewer 92
Working in Layout View Mode 92
Optimizing Your User Interface 94
Working in Pixel Perfect Mode 94
Working with Nine-Patch Stretchable Graphics 95
Working with Other Android Tools 98
Summary 99
References and More Information 100
PART II: ANDROID APPLICATION BASICS
Chapter 5 Understanding the Anatomy of an Android Application 103
Mastering Important Android Terminology 103
Using the Application Context 104
Retrieving the Application Context 104
Using the Application Context 104
Performing Application Tasks with Activities 106
The Lifecycle of an Android Activity 106
Organizing Activity Components with Fragments 111
Managing Activity Transitions with Intents 113
Transitioning Between Activities with Intents 113
Organizing Application Navigation with Activities and Intents 115
Working with Services 116
Receiving and Broadcasting Intents 117
Summary 117
References and More Information 118
Chapter 6 Defining Your Application Using the Android Manifest File 119
Configuring Android Applications Using the Android Manifest File 119
Editing the Android Manifest File 120
Managing Your Application’s Identity 124
Versioning Your Application 125
Setting the Application Name and Icon 125
Enforcing Application System Requirements 125
Targeting Specific SDK Versions 126
Enforcing Application Platform Requirements 129
Working with External Libraries 130
Other Application Configuration Settings and Filters 131
Registering Activities in the Android Manifest 131
Designating a Primary Entry Point Activity for Your Application Using an Intent Filter 132
Configuring Other Intent Filters 132
Registering Other Application Components 133
Working with Permissions 133
Registering Permissions Your Application Requires 133
Registering Permissions Your Application Enforces 134
Exploring Other Manifest File Settings 135
Summary 136
References and More Information 136
Chapter 7 Managing Application Resources 137
What Are Resources? 137
Storing Application Resources 137
Resource Value Types 138
Accessing Resources Programmatically 142
Setting Simple Resource Values Using Eclipse 143
Working with Different Types of Resources 146
Working with String Resources 146
Using String Resources as Format Strings 147
Working with String Arrays 149
Working with Boolean Resources 149
Working with Integer Resources 150
Working with Colors 151
Working with Dimensions 152
Working with Simple Drawables 153
Working with Images 154
Working with Animation 156
Working with Menus 158
Working with XML Files 159
Working with Raw Files 160
References to Resources 161
Working with Layouts 162
Referencing System Resources 167
Summary 168
References and More Information 168
PART III: ANDROID USER INTERFACE DESIGN ESSENTIALS
Chapter 8 Exploring User Interface Screen Elements 171
Introducing Android Views and Layouts 171
Introducing the Android View 171
Introducing the Android Controls 171
Introducing the Android Layout 172
Displaying Text to Users with TextView 173
Configuring Layout and Sizing 173
Creating Contextual Links in Text 174
Retrieving Data from Users with EditText 176
Retrieving Text Input Using EditText Controls 176
Constraining User Input with Input Filters 178
Helping the User with Autocompletion 179
Giving Users Choices Using Spinner Controls 181
Allowing Simple User Selections with Buttons, Check Boxes, Switches, and Radio Groups 183
Using Basic Buttons 184
Using CheckBox and ToggleButton Controls 186
Using RadioGroup and RadioButton 187
Retrieving Dates and Times from Users 190
Using Indicators to Display Data to Users 191
Indicating Progress with ProgressBar 192
Adjusting Progress with SeekBar 194
Displaying Rating Data with RatingBar 194
Showing Time Passage with the Chronometer 195
Displaying the Time 196
Summary 197
References and More Information 198
Chapter 9 Designing User Interfaces with Layouts 199
Creating User Interfaces in Android 199
Creating Layouts Using XML Resources 199
Creating Layouts Programmatically 201
Organizing Your User Interface 203
Using ViewGroup Subclasses for Layout Design 204
Using ViewGroup Subclasses as View Containers 204
Using Built-in Layout Classes 205
Using FrameLayout 207
Using LinearLayout 209
Using RelativeLayout 211
Using TableLayout 214
Using GridLayout 216
Using Multiple Layouts on a Screen 220
Using Container Control Classes 220
Using Data-Driven Containers 221
Organizing Screens with Tabs 226
Adding Scrolling Support 229
Exploring Other View Containers 230
Summary 231
References and More Information 231
Chapter 10 Working with Fragments 233
Understanding Fragments 233
Understanding the Fragment Lifecycle 234
Working with Special Types of Fragments 237
Designing Fragment-Based Applications 238
Using the Android Support Package 247
Adding Fragment Support to Legacy Applications 247
Using Fragments in New Applications Targeting Older Platforms 248
Linking the Android Support Package to Your Project 248
Summary 249
References and More Information 250
Chapter 11 Working with Dialogs 251
Choosing Your Dialog Implementation 251
Exploring the Different Types of Dialogs 252
Working with Dialogs: The Legacy Method 253
Tracing the Lifecycle of a Dialog 254
Working with Custom Dialogs 256
Working with Dialogs: The Fragment Method 257
Summary 260
References and More Information 260
PART IV: ANDROID APPLICATION DESIGN ESSENTIALS
Chapter 12 Using Android Preferences 263
Working with Application Preferences 263
Determining When Preferences Are Appropriate 263
Storing Different Types of Preference Values 264
Creating Private Preferences for Use by a Single Activity 264
Creating Shared Preferences for Use by Multiple Activities 265
Searching and Reading Preferences 265
Adding, Updating, and Deleting Preferences 266
Reacting to Preference Changes 267
Finding Preferences Data on the Android File System 267
Creating Manageable User Preferences 268
Creating a Preference Resource File 269
Using the PreferenceActivity Class 270
Summary 273
References and More Information 273
Chapter 13 Working with Files and Directories 275
Working with Application Data on the Device 275
Practicing Good File Management 276
Understanding Android File Permissions 277
Working with Files and Directories 277
Exploring with the Android Application Directories 278
Working with Other Directories and Files on the Android File System 282
Summary 284
References and More Information 284
Chapter 14 Using Content Providers 285
Exploring Android’s Content Providers 285
Using the MediaStore Content Provider 286
Using the CallLog Content Provider 288
Using the Browser Content Provider 289
Using the CalendarContract Content Provider 291
Using the UserDictionary Content Provider 291
Using the VoicemailContract Content Provider 291
Using the Settings Content Provider 292
Using the Contacts Content Providers 292
Modifying Content Providers Data 297
Adding Records 297
Updating Records 298
Deleting Records 298
Using Third-Party Content Providers 299
Summary 300
References and More Information 300
Chapter 15 Designing Compatible Applications 301
Maximizing Application Compatibility 301
Designing User Interfaces for Compatibility 303
Working with Fragments 305
Leveraging the Android Support Package 305
Supporting Specific Screen Types 305
Working with Nine-Patch Stretchable Graphics 306
Using the Working Square Principle 306
Providing Alternative Application Resources 308
Understanding How Resources Are Resolved 308
Organizing Alternative Resources with Qualifiers 309
Providing Resources for Different Orientations 316
Using Alternative Resources Programmatically 316
Organizing Application Resources Efficiently 316
Targeting Tablets, TVs, and Other New Devices 318
Targeting Tablet Devices 318
Targeting Google TV Devices 319
Summary 321
References and More Information 321
PART V: PUBLISHING AND DISTRIBUTING ANDROID APPLICATIONS
Chapter 16 The Android Software Development Process 325
An Overview of the Mobile Development Process 325
Choosing a Software Methodology 326
Understanding the Dangers of Waterfall Approaches 326
Understanding the Value of Iteration 327
Gathering Application Requirements 327
Determining Project Requirements 327
Developing Use Cases for Mobile Applications 329
Incorporating Third-Party Requirements 330
Managing a Device Database 330
Assessing Project Risks 333
Identifying Target Devices 333
Acquiring Target Devices 335
Determining the Feasibility of Application Requirements 336
Understanding Quality Assurance Risks 336
Writing Essential Project Documentation 337
Developing Test Plans for Quality Assurance Purposes 338
Providing Documentation Required by Third Parties 338
Providing Documentation for Maintenance and Porting 338
Leveraging Configuration Management Systems 339
Choosing a Source Control System 339
Implementing an Application Version System That Works 339
Designing Mobile Applications 340
Understanding Mobile Device Limitations 340
Exploring Common Mobile Application Architectures 340
Designing for Extensibility and Maintenance 341
Designing for Application Interoperability 342
Developing Mobile Applications 342
Testing Mobile Applications 343
Deploying Mobile Applications 343
Determining Target Markets 344
Supporting and Maintaining Mobile Applications 344
Track and Address Crashes Reported by Users 345
Testing Firmware Upgrades 345
Maintaining Adequate Application Documentation 345
Managing Live Server Changes 345
Identifying Low-Risk Porting Opportunities 345
Summary 346
References and More Information 346
Chapter 17 Designing and Developing Bulletproof Android Applications 347
Best Practices in Designing Bulletproof Mobile Applications 347
Meeting Mobile Users’ Demands 348
Designing User Interfaces for Mobile Devices 348
Designing Stable and Responsive Mobile Applications 349
Designing Secure Mobile Applications 351
Designing Mobile Applications for Maximum Profit 351
Leveraging Third-Party Quality Standards 352
Designing Mobile Applications for Ease of Maintenance and Upgrades 353
Leveraging Android Tools for Application Design 354
Avoiding Silly Mistakes in Android Application Design 355
Best Practices in Developing Bulletproof Mobile Applications 355
Designing a Development Process That Works for Mobile Development 356
Testing the Feasibility of Your Application Early and Often 356
Using Coding Standards, Reviews, and Unit Tests to Improve Code Quality 357
Handling Defects Occurring on a Single Device 359
Leveraging Android Tools for Development 360
Avoiding Silly Mistakes in Android Application Development 360
Summary 361
References and More Information 361
Chapter 18 Testing Android Applications 363
Best Practices in Testing Mobile Applications 363
Designing a Mobile Application Defect Tracking System 363
Managing the Testing Environment 365
Maximizing Testing Coverage 367
Leveraging Android Tools for Android Application Testing 374
Avoiding Silly Mistakes in Android Application Testing 375
Summary 376
References and More Information 376
Chapter 19 Publishing Your Android Application 377
Choosing the Right Distribution Model 377
Protecting Your Intellectual Property 378
Billing the User 379
Packaging Your Application for Publication 380
Preparing Your Code for Packaging 380
Packing and Signing Your Application 382
Testing the Release Version of Your Application Package 384
Distributing Your Application 385
Publishing on the Android Market 385
Signing Up for a Developer Account on the Android Market 385
Uploading Your Application to the Android Market 387
Uploading Application Marketing Assets 388
Configuring Application Listing Details 388
Configuring Application Publishing Options 390
Configuring Application Contact and Consent Information 390
Publishing Your Application on the Android Market 392
Managing Your Application on the Android Market 392
Publishing Using Other Alternatives 393
Self-Publishing Your Application 394
Summary 395
References and More Information 395
PART VI: APPENDIXES
Appendix A The Android Emulator Quick-Start Guide 399
Simulating Reality: The Emulator’s Purpose 399
Working with Android Virtual Devices (AVDs) 401
Using the Android Virtual Device Manager 402
Creating an AVD 403
Launching the Emulator with a Specific AVD 407
Maintaining Emulator Performance 407
Configuring Emulator Startup Options 408
Launching an Emulator to Run an Application 408
Launching an Emulator from the Android Virtual Device Manager 410
Configuring the GPS Location of the Emulator 411
Calling Between Two Emulator Instances 413
Messaging between Two Emulator Instances 415
Interacting with the Emulator through the Console 416
Using the Console to Simulate Incoming Calls 416
Using the Console to Simulate SMS Messages 416
Using the Console to Send GPS Coordinates 418
Using the Console to Monitor Network Status 418
Using the Console to Manipulate Power Settings 418
Using Other Console Commands 419
Enjoying the Emulator 419
Understanding Emulator Limitations 420
References and More Information 421
Appendix B The Android DDMS Quick-Start Guide 423
Using DDMS with Eclipse and as a Standalone Application 423
Getting Up to Speed Using Key Features of DDMS 424
Working with Processes, Threads, and the Heap 425
Attaching a Debugger to an Android Application 425
Stopping a Process 426
Monitoring Thread Activity of an Android Application 426
Monitoring Heap Activity 427
Prompting Garbage Collection 428
Creating and Using an HPROF File 429
Using the Allocation Tracker 430
Working with the File Explorer 430
Browsing the File System of an Emulator or Device 432
Copying Files from the Emulator or Device 432
Copying Files to the Emulator or Device 433
Deleting Files on the Emulator or Device 433
Working with the Emulator Control 434
Simulating Incoming Voice Calls 434
Simulating Incoming SMS Messages 434
Sending a Location Fix 435
Taking Screen Captures of the Emulator and Device Screens 435
Working with Application Logging 436
Appendix C Eclipse IDE Tips and Tricks 439
Organizing Your Eclipse Workspace 439
Integrating with Source Control Services 439
Repositioning Tabs within Perspectives 440
Maximizing Windows 440
Minimizing Windows 440
Viewing Windows, Side by Side 440
Viewing Two Sections of the Same File 441
Closing Unwanted Tabs 441
Keeping Windows Under Control 441
Creating Custom Log Filters 441
Searching Your Project 442
Organizing Eclipse Tasks 442
Writing Code in Java 443
Using Autocomplete 443
Creating New Classes and Methods 443
Organizing Imports 443
Formatting Code 444
Renaming Almost Anything 444
Refactoring Code 444
Reorganizing Code 446
Using QuickFix 446
Providing Javadoc-Style Documentation 446
Resolving Mysterious Build Errors 447
Index 449