Beginning Android 4

Book description

Beginning Android 4 is your first step on the path to creating marketable apps for the burgeoning Android Market, Amazon's Android Appstore, and more. Google's Android operating-system has taken the industry by storm, going from its humble beginnings as a smartphone operating system to its current status as a platform for apps that run across a gamut of devices from phones to tablets to netbooks to televisions, and the list is sure to grow.

Smart developers are not sitting idly by in the stands, but are jumping into the game of creating innovative and salable applications for this fast-growing, mobile- and consumer-device platform. If you're not in the game yet, now is your chance!

Beginning Android 4 is fresh with details on the latest iteration of the Android platform. Begin at the beginning by installing the tools and compiling a skeleton app. Move through creating layouts, employing widgets, taking user input, and giving back results. Soon you'll be creating innovative applications involving multi-touch, multi-tasking, location-based feature sets using GPS.

You'll be drawing data live from the Internet using web services and delighting your customers with life-enhancing apps. Not since the PC era first began has there been this much opportunity for the common developer. What are you waiting for? Grab your copy of Beginning Android 4 and get started!

What you'll learn

  • Develop Java-based mobile applications and games for a wide range of phones and devices.

  • Create user interfaces using WebKit and the Android widget framework.

  • Build location- and map-based applications drawing on live feeds over the Internet.

  • Incorporate activities, services, content providers, and broadcast receivers into your applications.

  • Support multiple Android versions, multiple screen sizes, and other device-specific characteristics.

  • Build and experience the array of new WebM video and other multimedia APIs for Android and more.

Who this book is for

Beginning Android 4 is aimed at programmers new to Android application development who desire to create marketable applications for the burgeoning market of smartphone, tablet, and other Android device users.

Table of contents

  1. Title
  2. Contents at a Glance
  3. Contents
  4. About the Author
  5. About the Technical Reviewers
  6. Acknowledgments
  7. Preface
    1. Welcome to the Book!
    2. Prerequisites
    3. Editions of This Book
    4. Source Code and Its License
  8. Part I: Core Concept
    1. Chapter 1: The Big Picture
      1. Benefits and Drawbacks of Smartphone Programming
      2. What Androids Are Made Of
      3. Stuff at Your Disposal
      4. The Big Picture...of This Book
    2. Chapter 2: How to Get Started
      1. Step 1: Set Up Java
      2. Step 2: Install the Android SDK
      3. Step 3: Install the ADT for Eclipse
      4. Step 4: Install Apache Ant
      5. Step 5: Set Up the Emulator
      6. Step 6: Set Up the Device
    3. Chapter 3: Your First Android Project
      1. Step 1: Create the New Project
      2. Step 2: Build, Install, and Run the Application in Your Emulator or Device
    4. Chapter 4: Examining Your First Project
      1. Project Structure
      2. Inside Your Manifest
    5. Chapter 5: A Bit About Eclipse
      1. What the ADT Gives You
      2. Coping with Eclipse
      3. Alternative IDEs
      4. IDEs and This Book
    6. Chapter 6: Enhancing Your First Project
      1. Supporting Multiple Screen Sizes
      2. Specifying Versions
  9. Part II: Activities
    1. Chapter 7: Rewriting Your First Project
      1. The Activity
      2. Dissecting the Activity
      3. Building and Running the Activity
    2. Chapter 8: 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
    3. Chapter 9: 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. Throw the Switch, Igor
      7. Turn Up the Radio
      8. It's Quite a View
    4. Chapter 10: Working with Containers
      1. Thinking Linearly
      2. All Things Are Relative
      3. Tabula Rasa
      4. Scrollwork
      5. Take Them to the Grid
    5. Chapter 11: 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. Jane, Stop This Crazy Thing!
    6. Chapter 12: Using Selection Widgets
      1. Adapting to the Circumstances
      2. Lists of Naughty and Nice
      3. Selection Modes
      4. Spin Control
      5. Grid Your Lions (or Something Like That...)
      6. Fields: Now with 35% Less Typing!
      7. Galleries, Give or Take the Art
    7. Chapter 13: Getting Fancy with Lists
      1. Getting to First Base
      2. A Dynamic Presentation
      3. Inflating Rows Ourselves
      4. Better. Stronger. Faster.
      5. Interactive Rows
    8. Chapter 14: Still More Widgets and Containers
      1. Pick and Choose
      2. Time Keeps Flowing Like a River
      3. Seeking Resolution
      4. Putting It on My Tab
      5. Flipping Them Off
      6. Getting in Somebody’s Drawer
      7. Other Good Stuff
    9. Chapter 15: 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!)
    10. Chapter 16: Applying Menus
      1. Flavors of Menu
      2. Menus of Options
      3. Menus in Context
      4. Taking a Peek
      5. Yet More Inflation
      6. When Giant Menus Walk the Earth
    11. Chapter 17: Showing Pop-Up Messages
      1. Raising Toasts
      2. Alert! Alert!
      3. Checking Them Out
    12. Chapter 18: Handling Activity Lifecycle Events
      1. Schrödinger’s Activity
      2. Life, Death, and Your Activity
      3. The Grace of State
    13. 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
    14. Chapter 20: Dealing with Threads
      1. The Main Application Thread
      2. Making Progress with ProgressBars
      3. Getting Through the Handlers
      4. Where Oh Where Has My UI Thread Gone?
      5. Asyncing Feeling
      6. Threads and Rotation
      7. And Now, the Caveats
    15. Chapter 21: Creating Intent Filters
      1. What’s Your Intent?
      2. Stating Your Intent(ions)
      3. Narrow Receivers
      4. Intents for Every Occasion
      5. The Pause Caveat
    16. Chapter 22: Launching Activities and Subactivities
      1. Peers and Subs
      2. Start ’Em Up
      3. Tabbed Browsing, Sort Of
    17. Chapter 23: Working with Resources
      1. The Resource Lineup
      2. String Theory
      3. Got the Picture?
      4. XML: The Resource Way
      5. Miscellaneous Values
      6. Different Strokes for Different Folks
      7. RTL Languages: Going Both Ways
    18. Chapter 24: Defining and Using Styles
      1. Styles: DIY DRY
      2. Elements of Style
      3. Themes: A Style by Any Other Name…
  10. Part III: Honeycomb and Tablets
    1. Chapter 25: Handling Multiple Screen Sizes
      1. Taking the Default
      2. Whole in One
      3. Tailor-Made, Just for You (and You, and You, and…)
      4. Ain't Nothing Like the Real Thing
      5. Ruthlessly Exploiting the Situation
      6. Example: EU4You
    2. Chapter 26: Focusing on Tablets and Larger UIs
      1. Why the Drive to Tablets?
      2. What the User Sees
      3. Dealing with the Rest of the Devices
    3. Chapter 27: Using the Action Bar
      1. Enabling the Action Bar
      2. Promoting Menu Items to the Action Bar
      3. Responding to the Logo
      4. Adding Custom Views to the Action Bar
      5. Don't Forget the Phones!
    4. Chapter 28: Fragments
      1. Introducing Fragments
      2. Creating Fragment Classes
      3. Fragments, Layouts, Activities, and Multiple Screen Sizes
      4. Fragments and Configuration Changes
      5. Designing for Fragments
    5. Chapter 29: Handling Platform Changes
      1. Things That Make You Go Boom
      2. Handling API Changes
      3. Patterns for Ice Cream Sandwich and Honeycomb
  11. Part IV: Data Stores, Network Services, and APIs
    1. Chapter 30: Accessing Files
      1. You and the Horse You Rode in On
      2. Readin' 'n Writin'
      3. External Storage: Giant Economy-Size Space
      4. StrictMode: Avoiding Janky Code
      5. Linux File Systems: You Sync, You Win
    2. Chapter 31: Using Preferences
      1. Getting What You Want
      2. Stating Your Preference
      3. Introducing PreferenceFragment and PreferenceActivity
      4. Preferences via Fragments
      5. Preferences the New and Improved Way
      6. Letting Users Have Their Say
      7. Adding a Wee Bit o' Structure
      8. The Kind of Pop-Ups You Like
    3. Chapter 32: Managing and Accessing Local Databases
      1. A Quick SQLite Primer
      2. Start at the Beginning
      3. Setting the Table
      4. Makin' Data
      5. What Goes Around, Comes Around
      6. Flash: Sounds Faster Than It Is
      7. Ship Ahoy!
      8. Data, Data, Everywhere
    4. Chapter 33: Leveraging Java Libraries
      1. Ants and JARs
      2. The Outer Limits
      3. Following the Script
      4. Reviewing the Script
    5. Chapter 34: Communicating via the Internet
      1. REST and Relaxation
      2. Leveraging Internet-Aware Android Components
      3. Continuing Our Escape from Janky Code
  12. Part V: Services
    1. Chapter 35: Services: The Theory
      1. Why Services?
      2. Setting Up a Service
      3. Communicating to Services
      4. Communicating from Services
    2. Chapter 36: Basic Service Patterns
      1. The Downloader
      2. The Music Player
      3. The Web Service Interface
    3. Chapter 37: Alerting Users via Notifications
      1. Notification Configuration
      2. Notifications in Action
      3. Staying in the Foreground
      4. Notifications in Ice Cream Sandwich and Honeycomb
  13. Part VI: Other Android Capabilities
    1. Chapter 38: Requesting and Requiring Permissions
      1. Mother, May I?
      2. Halt! Who Goes There?
      3. May I See Your Documents?
      4. New Permissions in Old Applications
      5. Permissions: Up Front or Not at All
    2. Chapter 39: 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?
      5. Testing... Testing...
    3. Chapter 40: Mapping with MapView and MapActivity
      1. Terms, Not of Endearment
      2. Piling On
      3. The Key to It All
      4. The Bare Bones
      5. Exercising Your Control
      6. Layers Upon Layers
      7. My, Myself, and MyLocationOverlay
      8. Rugged Terrain
      9. Maps and Fragments
    4. Chapter 41: Handling Telephone Calls
      1. Report to the Manager
      2. You Make the Call!
      3. No, Really, You Make the Call!
    5. Chapter 42: Fonts
      1. Love the One You're With
      2. Additional Fonts
      3. Here a Glyph, There a Glyph
    6. Chapter 43: More Development Tools
      1. Hierarchy Viewer: How Deep Is Your Code?
      2. DDMS: Under Android's Hood
      3. adb: Like DDMS, with More Typing
      4. Getting Graphical
  14. Part VII: Alternative Application Environments
    1. Chapter 44: The Role of Alternative Environments
      1. In the Beginning, There Was Java...
      2. ...And It Was OK
      3. Bucking the Trend
      4. Support, Structure
      5. Caveat Developer
    2. Chapter 45: HTML5
      1. Offline Applications
      2. Web Storage
      3. Going to Production
      4. Issues You May Encounter
      5. Browser Changes Post Ice Cream Sandwich
      6. HTML5 and Alternative Android Browsers
      7. HTML5: The Baseline
    3. Chapter 46: PhoneGap
      1. What Is PhoneGap?
      2. Using PhoneGap
      3. PhoneGap and the Checklist Sample
      4. Issues You May Encounter
      5. For More Information
    4. Chapter 47: Other Alternative Environments
      1. Rhodes
      2. Flash, Flex, and AIR
      3. JRuby and Ruboto
      4. Mono for Android
      5. App Inventor
      6. Titanium Mobile
      7. Other JVM Compiled Languages
  15. Part VIII: The Ever-Evolving Android
    1. Chapter 48: Dealing with Devices
      1. This App Contains Explicit Instructions
      2. A Guaranteed Market
      3. Other Stuff That Varies
      4. Bugs, Bugs, Bugs
      5. Device Testing
    2. Chapter 49: Where Do We Go from Here?
      1. Questions, Sometimes with Answers
      2. Heading to the Source
      3. Getting Your News Fix
  16. Index

Product information

  • Title: Beginning Android 4
  • Author(s):
  • Release date: December 2011
  • Publisher(s): Apress
  • ISBN: 9781430239840