Cover image for Learning Android, 2nd Edition

Book description

Want to build apps for Android devices? This book is the perfect way to master the fundamentals. Written by experts who have taught this mobile platform to hundreds of developers in large organizations and startups alike, this gentle introduction shows experienced object-oriented programmers how to use Android’s basic building blocks to create user interfaces, store data, connect to the network, and more.

Table of Contents

  1. Special Upgrade Offer
  2. Preface
    1. What’s Inside
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
      1. Marko Gargenta
      2. Masumi Nakamura
  3. 1. Android Overview
    1. Android Overview
      1. Comprehensive
      2. Open Source Platform
      3. Designed for Mobile Devices
    2. History
      1. Google’s Motivation
      2. Android Compatibility
      3. Open Handset Alliance
    3. Android Versions
    4. Android Flavors
      1. Android Open Source Project
      2. Manufacturer Add-Ons
    5. Summary
  4. 2. Java Review
    1. Comments
    2. Data Types: Primitives and Objects
    3. Modifiers
    4. Arrays
    5. Operators
    6. Control Flow Statements
    7. Error/Exception Handling
    8. Complex Example
    9. Interfaces and Inheritance
    10. Collections
    11. Generics
    12. Threads
    13. Summary
  5. 3. The Stack
    1. Stack Overview
    2. Linux
      1. Android != Linux
    3. Native Layer
      1. HAL
      2. Native Libraries
      3. Native Daemons
      4. Native Tools
    4. Dalvik
      1. Android and Java
    5. Application Framework
    6. Applications
      1. Android Application Package (APK)
      2. Application Signing
      3. Application Distribution
        1. Google Play
        2. Other markets
        3. Side-loading apps
        4. What about viruses, malware, spyware, and other bad things?
    7. Summary
  6. 4. Installing and Beginning Use of Android Tools
    1. Installing Java Development Kit
    2. Installing the Android SDK
      1. Setting Up a PATH to Tools
      2. Installing Eclipse
      3. Eclipse Workspace
      4. Setting Up Android Development Tools
    3. Hello World!
      1. Creating a New Project
    4. Anatomy of an Android Project
      1. Android Manifest File
      2. String Resources
      3. Layout XML Code
    5. Drawable Resources
      1. The R File
      2. Java Source Code
    6. Building the Project
    7. Android Emulator
      1. An Emulator Versus a Physical Phone
    8. Summary
  7. 5. Main Building Blocks
    1. A Real-World Example
    2. Activities
      1. Activity Life Cycle
        1. Starting state
        2. Running state
        3. Paused state
        4. Stopped state
        5. Destroyed state
    3. Intents
    4. Services
    5. Content Providers
    6. Broadcast Receivers
    7. Application Context
    8. Summary
  8. 6. Yamba Project Overview
    1. The Yamba Application
    2. Design Philosophy
    3. Project Design
    4. Part 1: Android User Interface
    5. Part 2: Intents, ActionBar, and More
    6. Part 3: Android Services
    7. Part 4: Content Providers
    8. Part 5: Lists and Adapters
    9. Part 6: Broadcast Receivers
    10. Part 7: App Widgets
    11. Part 8: Networking and the Web (HTTP)
    12. Part 9: Live Wallpaper and Handlers
    13. Summary
  9. 7. Android User Interface
    1. Two Ways to Create a User Interface
      1. Declarative User Interface
      2. Programmatic User Interface
      3. The Best of Both Worlds
    2. Views and Layouts
      1. LinearLayout
      2. TableLayout
      3. FrameLayout
      4. RelativeLayout
    3. Starting the Yamba Project
    4. The StatusActivity Layout
      1. Important Widget Properties
      2. Strings Resource
    5. The StatusActivity Java Class
      1. Inflating XML to Java
      2. Initializing Objects
      3. Handling User Events
    6. Logging Messages in Android
      1. LogCat
      2. Compiling Code and Building Your Projects: Saving Files
      3. Adding the Twitter API Library
      4. Updating the Manifest File for Internet Permission
    7. Threading in Android
      1. Single Thread
      2. Multithreaded Execution
      3. AsyncTask
    8. Other UI Events
    9. Alternative Resources
    10. Summary
  10. 8. Fragments
    1. Fragment Example
    2. Fragment Life Cyle
    3. Dynamically Adding Fragments
    4. Summary
  11. 9. Intents, Action Bar, and More
    1. Preferences
      1. Preference Resource
      2. SettingsActivity
      3. Update the Manifest File
    2. The Action Bar
      1. Creating a Blank Main Activity
      2. The Menu Resource
      3. Android System Resources
      4. Loading the Menu
      5. Updating StatusActivity to Handle Menu Events
    3. Shared Preferences and Updating Status Fragment
    4. The Filesystem Explained
      1. Exploring the Filesystem
      2. Filesystem Partitions
      3. System Partition
      4. SDCard Partition
      5. The User Data Partition
      6. Filesystem Security
    5. Summary
  12. 10. Services
    1. Our Example Service: RefreshService
      1. Creating the RefreshService Java Class
      2. Introducing IntentService
      3. Update the Manifest File
      4. Add Menu Items
      5. Update the Options Menu Handling
      6. Testing the Service
    2. Pulling Data from Yamba
      1. Testing the Service
    3. Summary
  13. 11. Content Providers
    1. Databases on Android
      1. About SQLite
      2. DbHelper
      3. The Database Schema and Its Creation
      4. Four Major Operations
      5. Cursors
    2. Status Contract Class
    3. Update RefreshService
      1. Testing the Service
        1. Verify that the database was created
        2. Using sqlite3
    4. Content Providers
    5. Creating a Content Provider
      1. Defining the URI
      2. Getting the Data Type
      3. Inserting Data
      4. Updating Data
      5. Deleting Data
      6. Querying Data
      7. Updating the Android Manifest File
      8. Updating RefreshService
    6. Summary
  14. 12. Lists and Adapters
    1. MainActivity
    2. Basic MainActivity
    3. Timeline Fragment
      1. Creating a List Item Layout
    4. About Adapters
    5. Loading the Data
    6. Custom Logic via ViewBinder
    7. Details View
      1. Details Fragment
      2. Details Activity
      3. Register with the Manifest File
      4. Main Activity, Landscape View
      5. Updating TimelineFragment
    8. Summary
  15. 13. Broadcast Receivers
    1. About Broadcast Receivers
    2. BootReceiver
      1. Registering the BootReceiver with the Android Manifest File
      2. Testing the Boot Receiver
    3. Alarms and System Services
    4. Broadcasting Intents
      1. Notification Receiver
    5. Summary
  16. 14. App Widgets
    1. Using Content Providers Through Widgets
      1. Implementing the YambaWidget Class
      2. Creating the XML Layout
      3. Creating the AppWidgetProviderInfo File
      4. Updating the Manifest File
      5. Testing the Widget
    2. Summary
  17. 15. Networking and Web Overview
    1. Quick Example
    2. Networking Basics
    3. HTTP API
    4. Apache HTTP Client
    5. HttpUrlConnection
    6. Networking in the Background using AsyncTask and AsyncTaskLoader
    7. Summary
  18. 16. Interaction and Animation: Live Wallpaper and Handlers
    1. Live Wallpaper
    2. Handler
    3. Summary
  19. Index
  20. About the Authors
  21. Colophon
  22. Special Upgrade Offer
  23. Copyright