You are on page 1of 6

contentS

IntroductIon chApter 1: getting StArted With Android progrAmming

xv 1

What is Android?
Android Versions Features of Android Architecture of Android Android Devices in the Market The Android Market

2
2 3 3 4 6

Summary

wi

Eclipse Android SDK Android Development Tools (ADT) Creating Android Virtual Devices (AVDs) Creating Your First Android Application Anatomy of an Android Application

ra

Obtaining the Required Tools

nd

To

ols

6
7 7 7 11 14 22

th

Fr ee

rit e

25
27

Applying Styles and Themes to Activity Hiding the Activity Title Displaying a Dialog Window Displaying a Progress Dialog

PD

Understanding Activities

Ed it

chApter 2: ActivitieS And intentS

or

27
32 33 34 39

Linking Activities Using intents


Resolving Intent Filter Collision Returning Results from an Intent Passing Data Using an Intent Object

PD

Fi

ll

43
48 50 54

Calling Built-in Applications Using intents


Understanding the Intent Object Using Intent Filters Adding Categories

56
64 65 71

Displaying notifications Summary

73 78

COnTenTS

chApter 3: getting to knoW the Android uSer interFAce

81

Understanding the Components of a Screen


Views and ViewGroups LinearLayout AbsoluteLayout TableLayout RelativeLayout FrameLayout ScrollView

81
82 83 87 89 91 93 95

Adapting to Display Orientation Managing Changes to Screen Orientation

97

ols

Anchoring Views Resizing and Repositioning

98 101

TextView View Button, ImageButton, EditText, CheckBox, ToggleButton, RadioButton, and RadioGroup Views ProgressBar View AutoCompleteTextView View

Basic Views

Ed it

chApter 4: deSigning your uSer interFAce uSing vieWS

or

wi

Summary

th

Overriding Methods Defined in an Activity Registering Events for Views

Fr ee

Creating the User interface Programmatically Listening for Ui notifications

rit e

Persisting State Information during Changes in Configuration Detecting Orientation Changes Controlling the Orientation of the Activity

To

104
108 109 110

ra

nd

111 114
114 119

122
125

126
126 127 135 141

Picker Views
TimePicker View Displaying the TimePicker in a Dialog Window DatePicker View Displaying the DatePicker View in a Dialog Window

PD

Fi

ll

PD

144
144 147 149 153

List Views
ListView View Customizing the ListView Using the Spinner View

156
156 159 162

Summary

166

COnTenTS

chApter 5: diSplAying pictureS And menuS With vieWS

169

Using image Views to Display Pictures


Gallery and ImageView Views ImageSwitcher GridView

169
170 177 181

Using Menus with Views


Creating the Helper Methods Options Menu Context Menu

185
186 188 190

Some Additional Views Summary

193

ols

AnalogClock and DigitalClock Views WebView

194 194

Saving and Loading User Preferences Persisting Data to Files


Saving to Internal Storage Saving to External Storage (SD Card) Choosing the Best Storage Option Using Static Resources

rit e

ra

chApter 6: dAtA perSiStence


Using getSharedPreferences() Using getPreferences()

nd

To

200
203

203
204 208

Fr ee

209
209 214 216 217

Creating the DBAdapter Helper Class Using the Database Programmatically Adding Contacts Retrieving All the Contacts Retrieving a Single Contact Updating a Contact Deleting a Contact Upgrading the Database Pre-Creating the Database Bundling the Database with an Application

Creating and Using Databases

Ed it

or

wi

th

218
218 224 224 225 226 227 228 230 230 231

Summary
chApter 7: content providerS

PD

Fi

ll

PD

234
237

Sharing Data in Android Using a Content Provider


Predefined Query String Constants

237 238
243
xi

COnTenTS

Projections Filtering Sorting

246 246 247

Creating Your Own Content Providers


Using the Content Provider

247
256

Summary
chApter 8: meSSAging And netWorking

260
263

SMS Messaging
Sending SMS Messages Programmatically Getting Feedback After Sending the Message Sending SMS Messages Using Intent Receiving SMS Messages Updating an Activity from a BroadcastReceiver Invoking an Activity from a BroadcastReceiver Caveats and Warnings

263
264 267 269 270 273 277 280

Sending e-Mail networking


Downloading Binary Data Downloading Text Files Accessing Web Services Performing Asynchronous Calls

rit e

ra

nd

To

ols

281 284
286 288 291 296

Displaying Maps

PD

chApter 9: locAtion-BASed ServiceS


Creating the Project Obtaining the Maps API Key Displaying the Map Displaying the Zoom Control Changing Views Navigating to a Specific Location Adding Markers Getting the Location That Was Touched Geocoding and Reverse Geocoding

Ed it

Summary

or

wi

th

Fr ee

297
301

302
302 303 305 308 310 312 315 318 320

getting Location Data


Monitoring a Location

PD

Fi

ll

322
327

Summary

327

xii

COnTenTS

chApter 10: developing Android ServiceS

331

Creating Your Own Services


Performing Long-Running Tasks in a Service Performing Repeated Tasks in a Service Executing Asynchronous Tasks on Separate Threads Using IntentService

331
336 341 343

Communicating between a Service and an Activity Binding Activities to Services Summary


chApter 11: puBliShing Android ApplicAtionS
Versioning Digitally Signing Your Android Applications

346 350 356


359

To

Preparing for Publishing Deploying APK Files


Using the adb .exe Tool Using a Web Server Publishing on the Android Market Creating a Developer Profile Submitting Your Apps

ols

359
360 362

nd

rit e

ra

367
367 369 372 372 373

Workspaces Package Explorer Using Projects from Other Workspaces Editors Perspectives Auto Import of Namespaces Code Completion Refactoring

getting Around in eclipse

Ed it

Appendix A: uSing eclipSe For Android development

or

wi

Summary

th

Fr ee

378
3 81

381
381 382 383 385 387 387 388 388

Debugging
Setting Breakpoints Exceptions

PD

Fi

ll

PD

389
389 390

Appendix B: uSing the Android emulAtor

393

Uses of the Android emulator installing Custom AVDs

393 393

xiii

COnTenTS

emulating Real Devices SD Card emulation emulating Devices with Different Screen Sizes emulating Physical Capabilities Sending SMS Messages to the emulator Making Phone Calls Transferring Files into and out of the emulator Resetting the emulator
Appendix c: AnSWerS to exerciSeS

398 399 401 402 403 406 407 409


411

xiv

PD

Fi

ll

PD

Ed it

Index

or

wi

Chapter 1 Answers Chapter 2 Answers Chapter 3 Answers Chapter 4 Answers Chapter 5 Answers Chapter 6 Answers Chapter 7 Answers Chapter 8 Answers Chapter 9 Answers Chapter 10 Answers Chapter 11 Answers

411 411 412 412 412 413 413 413 413 414 414
415

th

Fr ee

rit e

ra

nd

To

ols