Preface xiv
New in the Third Edition xiv
Who This Book Is For xv
How This Book Is Organized xv
Part I: Getting Started
HOUR 1: Getting Started: Creating a Simple App 3
Setting Up Your Development Environment 3
Instantly Creating a Simple App 6
Understanding the Java Code and XML Layout 10
Running the App 11
Personalizing the App 13
Summary 17
Q&A 17
Workshop 18
Exercise 18
HOUR 2: Understanding an Android Activity 19
Understanding an Activity 19
Starting an Activity 20
Passing Information Between Activities 28
Understanding Intents 34
Understanding the Activity Lifecycle 38
Summary 41
Q&A 41
Workshop 42
Exercises 42
HOUR 3: Exploring an Android Project and Resources 43
Exploring the Android Project Files 43
Understanding Common Resources 47
Summary 57
Q&A 57
Workshop 57
Exercises 58
HOUR 4: Not Just Smartphones: Supporting Tablets, TVs, and More 59
A Brief History of Android 59
Handling Device Display and Orientation 60
Device Features 67
Platform Versions and the Compatibility Package 68
Launching Apps on a Device 72
Summary 74
Q&A 74
Workshop 75
Exercises 75
Part II: User Interface
HOUR 5: Using Layouts 79
Getting Started with Layouts 79
More Layout Basics with LinearLayout 84
Laying Out Child Views 86
FrameLayout 89
RelativeLayout 89
Summary 91
Q&A 92
Workshop 92
Exercises 93
HOUR 6: Working with Basic UI Controls 95
Setting Up the Demo App 95
Using Input Controls 98
Using Controls with Adapters 104
ProgressBars and SeekBars 107
ImageViews 110
Summary 111
Q&A 111
Workshop 112
Exercise 112
HOUR 7: ActionBar and Menu Navigation 113
Understanding the Options Menu 113
Using the Action Bar 120
Strategies for Using the ActionBar and Menus 124
Summary 125
Q&A 125
Workshop 126
Exercises 126
HOUR 8: Activities and Fragments 127
Using Fragments Across UIs 127
Creating and Displaying Fragments 128
Using Fragments for Navigation 132
Fragment and Activity Interaction 136
Summary 139
Q&A 139
Workshop 139
Exercises 140
HOUR 9: Alert! Working with Dialogs 141
Understanding a Dialog Fragment 141
Dialogs for Picking Date and Time 145
Using Alert Dialogs 151
Summary 155
Q&A 156
Workshop 156
Exercise 156
HOUR 10: Lists, Grids, Galleries, and Flippers 157
ListFragments 157
Grids and Galleries 162
Using an AdapterViewFlipper 166
Options for Paging Controls 167
Summary 168
Q&A 169
Workshop 169
Exercise 169
HOUR 11: App Setting: Managing Preferences 171
Using SharedPreferences 171
Setting User Preferences 174
Summary 185
Q&A 185
Workshop 186
Exercise 186
Part III: Data Access and Use
HOUR 12: Accessing the Cloud: Working with a Remote API 189
Fetching Remote Data 190
Using and Parsing JSON-Formatted Data 194
Putting the Pieces Together 197
Checking Connectivity 202
Summary 203
Q&A 203
Workshop 203
Exercise 204
HOUR 13: Using SQLite and File Storage 205
Organizing a Database with Tables 205
Managing Data with SQLiteOpenHelper 206
Adding, Updating, and Deleting Data 209
Querying Data and Using Cursors 212
Using a Database in the App 215
Saving an Image File 218
Summary 224
Q&A 224
Workshop 225
Exercises 225
HOUR 14: Creating a Content Provider 227
Using a URI for Data Retrieval 227
Building a Content Provider 228
Using FlickrPhotoProvider in the App 236
Requesting a File from a Content Provider 237
Summary 242
Q&A 242
Workshop 243
Exercises 243
HOUR 15: Loaders, CursorLoaders, and CustomAdapters 245
How Loaders Work 245
Loader Classes 246
Understanding Loader States 246
Creating Custom Adapters 253
Summary 257
Q&A 257
Workshop 258
Exercise 258
HOUR 16: Developing a Complete App 259
Determining App Functionality 259
Developing the App 263
Summary 278
Q&A 278
Workshop 278
Exercise 279
Part IV: Special Topics
HOUR 17: Contacts and Calendar: Accessing Device Data 283
All About the Calendar 283
Understanding Contacts 294
Summary 297
Q&A 297
Workshop 298
Exercise 298
HOUR 18: Where Are We? Working with Location-Based Services 299
Determining Location 299
Using Geocoding Services 306
Using the Geo Intent 309
Additional Location Features 311
Using Google Play Services 312
Summary 315
Q&A 316
Workshop 316
Exercise 316
HOUR 19: Bonjour, World! Localizing Your Apps 317
General Internationalization Principles 317
Working with Localization with Android 318
Handling Locales with Android 319
Using Applications to Handle Locales 320
Android Internationalization Strategies 323
Using Localization Utilities 326
Summary 327
Q&A 327
Workshop 327
Exercises 328
HOUR 20: Say Cheese! Working with Cameras 329
Capturing Media 329
Using Intents to Take Photos and Videos 332
Developing a Camera App 338
Summary 345
Q&A 346
Workshop 346
Exercise 346
HOUR 21: Media Basics: Images, Audio, and Video 347
Examining the ImageView Control 347
Bitmaps and Canvas 353
Using VideoViews 357
Playing Audio with MediaPlayer 361
Exploring More Media Options 362
Summary 362
Q&A 362
Workshop 363
Exercise 363
HOUR 22: Using the Facebook SDK 365
About Facebook 365
Setting Up for Facebook Development 366
Using the Facebook SDK in a Project 370
Developing a Facebook Photo Upload App 373
Facebook SDK Features 378
Creating Libraries for Your Own Projects 379
Summary 379
Q&A 380
Workshop 380
Exercise 380
Part V: Wrapping Up
HOUR 23: Pro Tips, Finishing Touches, and Next Steps 383
Responsive Apps: Using IntentService 383
Adding Animation 388
Using Open Source 391
Digging Deeper into Android 392
Summary 397
Q&A 397
Workshop 397
Exercise 398
HOUR 24: Publishing Your Apps 399
Preparing for Release 399
Publishing Your App 405
Monetizing Your App 409
Summary 410
Q&A 410
Workshop 410
Exercise 411
Index 413