Cover image for Learning Android

Book description

If you're new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. This gentle introduction shows you how to use Android's basic building blocks to develop user interfaces, store data, and more. You'll build an example application throughout the course of book, adding new features with each chapter. You'll also build your own toolbox of code patterns that will help you program any type of Android application with ease.

Table of Contents

  1. Learning Android
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. A Note Regarding Supplemental Files
    3. 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
    4. 1. Android Overview
      1. Android Overview
        1. Comprehensive
        2. Open Source Platform
        3. Designed for Mobile Devices
      2. History
        1. Google’s Motivation
        2. Open Handset Alliance
      3. Android Versions
      4. Summary
    5. 2. The Stack
      1. Stack Overview
      2. Linux
        1. Portability
        2. Security
        3. Features
      3. Native Libraries
      4. Dalvik
        1. Android and Java
      5. Application Framework
      6. Applications
        1. The APK
        2. Application Signing
        3. Application Distribution
          1. What about viruses, malware, spyware, and other bad things?
      7. Summary
    6. 3. Quick Start
      1. Installing the Android SDK
        1. Setting Up a PATH to Tools
        2. Installing Eclipse
        3. Eclipse Workspace
        4. Setting Up Android Development Tools
      2. Hello, World
        1. Creating a New Project
        2. Manifest File
        3. Layout XML Code
        4. Strings
        5. The R File
        6. Java Source Code
      3. The Emulator
        1. An Emulator Versus a Physical Phone
      4. Summary
    7. 4. Main Building Blocks
      1. What Are Main Building Blocks?
      2. A Real-World Example
      3. Activities
        1. Activity Life Cycle
          1. Starting state
          2. Running state
          3. Paused state
          4. Stopped state
          5. Destroyed state
      4. Intents
      5. Services
      6. Content Providers
      7. Broadcast Receivers
      8. Application Context
      9. Summary
    8. 5. Yamba Project Overview
      1. The Yamba Application
      2. Design Philosophy
      3. Project Design
      4. Part 1: Android User Interface
        1. Building an Activity
        2. Networking and Multithreading
        3. Debugging Android Apps
      5. Part 2: Preferences, Filesystem, Options Menu, and Intents
        1. The Activity
        2. Menu System and Intents
        3. Filesystem
      6. Part 3: Android Services
        1. Services
        2. Application Object
      7. Part 4: Working with Databases
        1. SQLite and Android’s Support for It
        2. Refactoring the Code Again
      8. Part 5: Lists and Adapters
        1. Timeline Activity
        2. More Refactoring?
      9. Part 6: Broadcast Receivers
        1. Boot and Network Receivers
        2. Timeline Receiver
        3. Permissions
      10. Part 7: Content Providers
        1. Status Data
        2. Android Widgets
      11. Part 8: System Services
        1. Compass and Location
        2. Intent Service, Alarms, and Notifications
      12. Summary
    9. 6. 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
        5. AbsoluteLayout
      3. Starting the Yamba Project
      4. The StatusActivity Layout
        1. Important Widget Properties
        2. Strings Resource
      5. The StatusActivity Java Class
        1. Creating Your Application-Specific Object and Initialization Code
        2. Compiling Code and Building Your Projects: Saving Files
        3. Adding the jtwitter.jar Library
        4. Updating the Manifest File for Internet Permission
      6. Logging in Android
        1. LogCat
          1. LogCat from the Eclipse DDMS perspective
          2. LogCat from the command line
      7. Threading in Android
        1. Single Thread
        2. Multithreaded Execution
        3. AsyncTask
      8. Other UI Events
      9. Adding Color and Graphics
        1. Adding Images
          1. Using the WYSIWYG editor in Eclipse
          2. Updating directly in XML code
        2. Adding Color
      10. Alternative Resources
      11. Optimizing the User Interface
        1. Hierarchy Viewer
      12. Summary
    10. 7. Preferences, the Filesystem, the Options Menu, and Intents
      1. Preferences
        1. Prefs Resource
        2. PrefsActivity
        3. Update the Manifest File
      2. The Options Menu
        1. The Menu Resource
        2. Android System Resources
        3. Update StatusActivity to Load the Menu
        4. Update StatusActivity to Handle Menu Events
        5. Strings Resource
      3. Shared Preferences
      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
    11. 8. Services
      1. The Yamba Application Object
        1. The YambaApplication Class
        2. Update the Manifest File
        3. Simplifying StatusActivity
      2. UpdaterService
        1. Creating the UpdaterService Java Class
        2. Update the Manifest File
        3. Add Menu Items
        4. Update the Options Menu Handling
        5. Testing the Service
      3. Looping in the Service
        1. Testing the Service
      4. Pulling Data from Twitter
        1. Testing the Service
      5. Summary
    12. 9. The Database
      1. About SQLite
      2. DbHelper
        1. The Database Schema and Its Creation
        2. Four Major Operations
        3. Cursors
      3. First Example
      4. Update UpdaterService
        1. Testing the Service
          1. Verify that the database was created
          2. Using sqlite3
        2. Database Constraints
      5. Refactoring Status Data
      6. Summary
    13. 10. Lists and Adapters
      1. TimelineActivity
      2. Basic TimelineActivity Layout
        1. Introducing ScrollView
        2. Creating the TimelineActivity Class
      3. About Adapters
        1. Adding a ListView to TimelineActivity
          1. ListView versus ListActivity
        2. Creating a Row Layout
        3. Creating an Adapter in TimelineActivity.java
      4. TimelineAdapter
      5. ViewBinder: A Better Alternative to TimelineAdapter
      6. Updating the Manifest File
        1. Initial App Setup
      7. Base Activity
        1. Toggle Service
      8. Summary
    14. 11. Broadcast Receivers
      1. About Broadcast Receivers
      2. BootReceiver
        1. Registering the BootReceiver with the AndroidManifest File
        2. Testing the Boot Receiver
      3. The TimelineReceiver
      4. Broadcasting Intents
      5. The Network Receiver
      6. Adding Custom Permissions to Send and Receive Broadcasts
        1. Declaring Permissions in the Manifest File
        2. Updating the Services to Enforce Permissions
        3. Updating TimelineReceiver to Enforce Permissions
      7. Summary
    15. 12. Content Providers
      1. Creating a Content Provider
        1. Defining the URI
        2. Inserting Data
        3. Updating Data
        4. Deleting Data
        5. Querying Data
        6. Getting the Data Type
        7. Updating the Android Manifest File
      2. 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
      3. Summary
    16. 13. System Services
      1. Compass Demo
        1. Common Steps in Using System Services
        2. Getting Updates from the Compass
        3. Compass Main Activity
        4. Custom Rose Widget
      2. Location Service
        1. Where Am I? Demo
          1. The layout
          2. The activity for our Location listener
          3. The manifest file
      3. Updating Yamba to Use the Location Service
        1. Updating Our Preferences
        2. Updating the Yamba Application
        3. Updating the Status Activity
      4. Intent Service
        1. Alarms
          1. Pending intents
        2. Adding an Interval to Preferences
        3. Updating BootReceiver
      5. Sending Notifications
      6. Summary
    17. 14. The Android Interface Definition Language
      1. Implementing the Remote Service
        1. Writing the AIDL
        2. Implementing the Service
        3. Implementing a Parcel
        4. Registering with the Manifest File
      2. Implementing the Remote Client
        1. Binding to the Remote Service
        2. Testing That It All Works
      3. Summary
    18. 15. The Native Development Kit (NDK)
      1. What Is and Isn’t the NDK For?
      2. Problems Solved by the NDK
        1. The Toolchain
        2. Packaging Your Libs
        3. Documentation and Standardized Headers
      3. An NDK Example: Fibonacci
        1. FibLib
        2. The JNI Header File
        3. C Implementation
        4. The Makefile
        5. Building the Shared Library
        6. The Fibonacci Activity
        7. Testing That It All Works
      4. Summary
    19. Index
    20. About the Author
    21. Colophon
    22. SPECIAL OFFER: Upgrade this ebook with O’Reilly