Beginning Android 2

Book description

The Android development platform, created by Google and the Open Handset Alliance, is a platform in its truest sense, encompassing hundreds of classes beyond the traditional Java classes and open source components that ship with the SDK.

With Beginning Android 2, you'll learn how to develop applications for Android 2.x mobile devices, using simple examples that are ready to run with your copy of the software development kit. Author, Android columnist, writer, developer, and community advocate Mark L. Murphy will show you what you need to know to get started programming Android applications, including how to craft graphical user interfaces, use GPS, and access web services.

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Author
  7. Acknowledgments
  8. Preface
    1. Welcome to the Book!
    2. Prerequisites
    3. Editions of This Book
    4. Source Code and Its License
  9. Chapter 1 The Big Picture
    1. Challenges of Smartphone Programming
    2. What Androids Are Made Of
    3. Stuff at Your Disposal
  10. Chapter 2 Projects and Targets
    1. Pieces and Parts
    2. Creating a Project
    3. Project Structure
      1. Root Contents
      2. The Sweat Off Your Brow
      3. And Now, the Rest of the Story
      4. What You Get Out of It
    4. Inside the Manifest
      1. In the Beginning, There Was the Root, And It Was Good
      2. Permissions, Instrumentations, and Applications (Oh My!)
      3. Your Application Does Something, Right?
      4. Achieving the Minimum
      5. Version=Control
    5. Emulators and Targets
      1. Virtually There
      2. Aiming at a Target
  11. Chapter 3 Creating a Skeleton Application
    1. Begin at the Beginning
    2. Dissecting the Activity
    3. Building and Running the Activity
  12. Chapter 4 Using XML-Based Layouts
    1. What Is an XML-Based Layout?
    2. Why Use XML-Based Layouts?
    3. OK, So What Does It Look Like?
    4. What's with the @ Signs?
    5. And How Do We Attach These to the Java?
    6. The Rest of the Story
  13. Chapter 5 Employing Basic Widgets
    1. Assigning Labels
    2. Button, Button, Who's Got the Button?
    3. Fleeting Images
    4. Fields of Green. Or Other Colors.
    5. Just Another Box to Check
    6. Turn the Radio Up
    7. It's Quite a View
    8. Useful Properties
      1. Useful Methods
      2. Colors
  14. Chapter 6 Working with Containers
    1. Thinking Linearly
      1. LinearLayout Concepts and Properties
      2. LinearLayout Example
    2. All Things Are Relative
      1. RelativeLayout Concepts and Properties
      2. RelativeLayout Example
    3. Tabula Rasa
      1. TableLayout Concepts and Properties
      2. TableLayout Example
    4. Scrollwork
  15. Chapter 7 Using Selectiosn Widgets
    1. Adapting to the Circumstances
    2. Lists of Naughty and Nice
    3. Spin Control
    4. Grid Your Lions (or Something Like That...)
    5. Fields: Now with 35% Less Typing!
    6. Galleries, Give or Take the Art
  16. Chapter 8 Getting Fancy with Lists
    1. Getting to First Base
    2. A Dynamic Presentation
    3. Better. Stronger. Faster.
      1. Using convertView
      2. Using the Holder Pattern
    4. Making a List…
      1. …And Checking It Twice
      2. Adapting Other Adapters
  17. Chapter 9 Employing Fancy Widgets and Containers
    1. Pick and Choose
    2. Time Keeps Flowing Like a River
    3. Making Progress
    4. Seeking Resolution
    5. Put It on My Tab
      1. The Pieces
      2. The Idiosyncrasies
      3. Wiring It Together
      4. Adding Them Up
      5. Intents and Views
    6. Flipping Them Off
      1. Manual Flipping
      2. Adding Contents on the Fly
      3. Automatic Flipping
    7. Getting in Someone’s Drawer
    8. Other Good Stuff
  18. Chapter 10 The Input Method Framework
    1. Keyboards, Hard and Soft
    2. Tailored to Your Needs
    3. Tell Android Where It Can Go
    4. Fitting In
    5. Unleash Your Inner Dvorak
  19. Chapter 11 Applying Menus
    1. Menus of Options
      1. Creating an Options Menu
      2. Adding Menu Choices and Submenus
    2. Menus in Context
    3. Taking a Peek
    4. Yet More Inflation
      1. Menu XML Structure
      2. Menu Options and XML
      3. Inflating the Menu
  20. Chapter 12 Fonts
    1. Love the One You're With
    2. More Fonts
    3. Here a Glyph, There a Glyph
  21. Chapter 13 Embedding the WebKit Browser
    1. A Browser, Writ Small
    2. Loading It Up
    3. Navigating the Waters
    4. Entertaining the Client
    5. Settings, Preferences, and Options (Oh My!)
  22. Chapter 14 Showing Pop-Up Messages
    1. Raising Toasts
    2. Alert! Alert!
    3. Checking Them Out
  23. Chapter 15 Dealing with Threads
    1. Getting Through the Handlers
      1. Messages
      2. Runnables
    2. Running in Place
    3. Where Oh Where Has My UI Thread Gone?
    4. Asyncing Feeling
      1. The Theory
      2. AsyncTask, Generics, and Varargs
      3. The Stages of AsyncTask
      4. A Sample Task
    5. And Now, the Caveats
  24. Chapter 16 Handling Activity Life Cycle Events
    1. Schroedinger's Activity
    2. Life, Death, and Your Activity
      1. onCreate() and onDestroy()
      2. onStart(), onRestart(), and onStop()
      3. onPause() and onResume()
    3. The Grace of State
  25. Chapter 17 Creating Intent Filters
    1. What's Your Intent?
      1. Pieces of Intents
      2. Intent Routing
    2. Stating Your Intent(ions)
    3. Narrow Receivers
    4. The Pause Caveat
  26. Chapter 18 Launching Activities and Subactivities
    1. Peers and Subs
    2. Start 'Em Up
      1. Make an Intent
      2. Make the Call
    3. Tabbed Browsing, Sort Of
  27. Chapter 19 Handling Rotation
    1. A Philosophy of Destruction
    2. It's All the Same, Just Different
    3. Now with More Savings!
    4. DIY Rotation
    5. Forcing the Issue
    6. Making Sense of It All
  28. Chapter 20 Working with Resources
    1. The Resource Lineup
    2. String Theory
      1. Plain Strings
      2. String Formats
      3. Styled Text
      4. Styled String Formats
    3. Got the Picture?
    4. XML: The Resource Way
    5. Miscellaneous Values
      1. Dimensions
      2. Colors
      3. Arrays
    6. Different Strokes for Different Folks
  29. Chapter 21 Using Preferences
    1. Getting What You Want
    2. Stating Your Preference
    3. And Now, a Word from Our Framework
    4. Letting Users Have Their Say
    5. Adding a Wee Bit o' Structure
    6. The Kind of Pop-Ups You Like
  30. Chapter 22 Managing and Accessing Local Databases
    1. The Database Example
    2. A Quick SQLite Primer
    3. Start at the Beginning
    4. Setting the Table
    5. Makin' Data
    6. What Goes Around Comes Around
      1. Raw Queries
      2. Regular Queries
      3. Building with Builders
      4. Using Cursors
    7. Data, Data, Everywhere
  31. Chapter 23 Accessing Files
    1. You and the Horse You Rode in On
    2. Readin’ ’n Writin’
  32. Chapter 24 Leveraging Java Libraries
    1. The Outer Limits
    2. Ants and JARs
    3. Following the Script
    4. ...And Not a Drop to Drink
    5. Reviewing the Script
  33. Chapter 25 Communicating via the Internet
    1. REST and Relaxation
    2. HTTP Operations via Apache HttpClient
    3. Parsing Responses
    4. Stuff to Consider
  34. Chapter 26 Using a Content Provider
    1. Pieces of Me
    2. Getting a Handle
    3. Makin' Queries
    4. Adapting to the Circumstances
    5. Give and Take
    6. Beware of the BLOB!
  35. Chapter 27 Building a Content Provider
    1. First, Some Dissection
    2. Next, Some Typing
    3. Creating Your Content Provider
      1. Step 1: Create a Provider Class
      2. Step 2: Supply a Uri
      3. Step 3: Declare the Properties
      4. Step 4: Update the Manifest
    4. Notify-on-Change Support
  36. Chapter 28 Requesting and Requiring Permissions
    1. Mother, May I?
    2. Halt! Who Goes There?
      1. Enforcing Permissions via the Manifest
      2. Enforcing Permissions Elsewhere
    3. May I See Your Documents?
  37. Chapter 29 Creating a Service
    1. Service with Class
    2. There Can Only Be One
    3. Manifest Destiny
    4. Lobbing One Over the Fence
      1. Callbacks
      2. Broadcast Intents
    5. Where's the Remote? And the Rest of the Code?
  38. Chapter 30 Invoking a Service
    1. The Ties That Bind
    2. Catching the Lob
  39. Chapter 31 Alerting Users via Notifications
    1. Types of Pestering
      1. Hardware Notifications
      2. Icons
    2. Seeing Pestering in Action
  40. Chapter 32 Accessing Location-Based Services
    1. Location Providers: They Know Where You're Hiding
    2. Finding Yourself
    3. On the Move
    4. Are We There Yet? Are We There Yet? Are We There Yet?
    5. Testing…Testing…
  41. Chapter 33 Mapping with MapView and MapActivity
    1. Terms, Not of Endearment
    2. Piling On
    3. The Bare Bones
    4. Exercising Your Control
      1. Zoom
      2. Center
    5. Rugged Terrain
    6. Layers upon Layers
      1. Overlay Classes
      2. Drawing the ItemizedOverlay
      3. Handling Screen Taps
    7. My, Myself, and MyLocationOverlay
    8. The Key to It All
  42. Chapter 34 Handling Telephone Calls
    1. Report to the Manager
    2. You Make the Call!
  43. Chapter 35 Development Tools
    1. Hierarchical Management
    2. Delightful Dalvik Debugging Detailed, Demoed
      1. Logging
      2. File Push and Pull
      3. Screenshots
      4. Location Updates
      5. Placing Calls and Messages
    3. Put It on My Card
      1. Creating a Card Image
      2. Inserting the Card
  44. Chapter 36 Handling Multiple Screen Sizes
    1. Taking the Default
    2. Whole in One
      1. Think About Rules, Rather Than Positions
      2. Consider Physical Dimensions
      3. Avoid Real Pixels
      4. Choose Scalable Drawables
    3. Tailor-Made, Just for You (and You, and You, and...)
      1. Add <supports-screens>
      2. Resources and Resource Sets
      3. Default Scaling
      4. Density-Based Sets
      5. Size-Based Sets
      6. Version-Based Sets
      7. Finding Your Size
    4. Ain't Nothing Like the Real Thing
      1. Density Differs
      2. Adjusting the Density
      3. Accessing Actual Devices
    5. Ruthlessly Exploiting the Situation
      1. Replace Menus with Buttons
      2. Replace Tabs with a Simple Activity
      3. Consolidate Multiple Activities
    6. Example: EU4You
      1. The First Cut
      2. Fixing the Fonts
      3. Fixing the Icons
      4. Using the Space
      5. What If It's Not a Browser?
    7. What Are a Few Bugs Among Friends?
  45. Chapter 37 Dealing with Devices
    1. This App Contains Explicit Instructions
    2. Button, Button, Who's Got the Button?
    3. A Guaranteed Market
    4. The Down and Dirty Details
    5. Archos 5 Android Internet Tablet
    6. Motorola CLIQ/DEXT
    7. Motorola DROID/Milestone
    8. Google/HTC Nexus One
    9. Motorola BACKFLIP
  46. Chapter 38 Handling Platform Changes
    1. Brand Management
    2. More Things That Make You Go Boom
      1. View Hierarchy
      2. Changing Resources
    3. Handling API Changes
      1. Detecting the Version
      2. Wrapping the API
  47. Chapter 39 Where Do We Go from Here?
    1. Questions—Sometimes with Answers
    2. Heading to the Source
    3. Getting Your News Fix
  48. Index

Product information

  • Title: Beginning Android 2
  • Author(s): Mark L. Murphy
  • Release date: March 2010
  • Publisher(s): Apress
  • ISBN: 9781430226291