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.

Throughout the book, you’ll build a Twitter-like application, adding new features with each chapter. You’ll also create your own toolbox of code patterns to help you program any type of Android application with ease.

  • Become familiar with the Android platform and how it fits into the mobile ecosystem
  • Dive into the Android stack, including its application framework and the APK application package
  • Learn Android’s building blocks: Activities, Intents, Services, Content Providers, and Broadcast Receivers
  • Create basic Android user interfaces and organize UI elements in Views and Layouts
  • Build a service that uses a background process to update data in your application

Publisher resources

View/Submit Errata

Table of contents

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 8. Fragments
    1. Fragment Example
    2. Fragment Life Cycle
    3. Dynamically Adding Fragments
    4. Summary
  10. 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 MainActivity 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 16. Interaction and Animation: Live Wallpaper and Handlers
    1. Live Wallpaper
    2. Handler
    3. Summary
  18. Index
  19. Colophon
  20. Copyright

Product information

  • Title: Learning Android, 2nd Edition
  • Author(s): Marko Gargenta, Masumi Nakamura
  • Release date: January 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449319236