My Cart (0)

Customer Service 1-800-221-5528

Murach’s Android Programming (2nd Edition)

by Joel Murach
18 chapters, 682 pages, 289 illustrations
Published December 2015
ISBN 978-1-890774-93-6
Print: $46.00
List Price: $57.50 Save 20%
eBook: $42.00
List Price: $52.50 Save 20%
Print + eBook: $56.00
List Price: $70.00 Save 20%

If you know how to program in Java, this is the first book you should buy for learning how to develop Android apps the way the pros do; it'll save you a lot of time and frustration. First, it shows how to set up a professional development environment using Android Studio. Then, it presents a series of complete Android apps that illustrate key skills…working with fragments, services, broadcast receivers, SQLite databases, content providers, Google Maps, and more! 

College Instructors

Go to our instructor’s site to learn more about this book and its instructor’s materials.

 

I like the fact that the book approaches the subject by using example apps as the theme of study, and working through the skills incrementally from easy to difficult. These case-study apps are complete apps by themselves and are worthy of being in the Android app stores.”

Jason Ong, ASP.NET World

  • About this Book
  • Table of Contents
  • FREE Downloads
  • Book FAQs
  • Corrections
  • Reviews

What this book does

This book is a great way to get started with Android programming. Here’s a brief rundown of its sections.

Section 1: Get started fast

In four chapters, you’ll quickly master the basics of Android programming. That includes:

  • essential concepts and terms for Android programming
  • how to use Android Studio to develop your first Android app, a simple but complete Tip Calculator app
  • how to use Android Studio to thoroughly test and debug your apps

Section 2: The essential Android skills

You’ll learn the Android essentials by enhancing the Tip Calculator app that you developed in section 1. Those essentials include:

  • how to use layouts and widgets to develop a sophisticated user interface
  • how to handle high- and low-level events
  • how to use themes and styles to format your app in a way that’s consistent and easy to maintain
  • how to use menus and preferences
  • how to use fragments to take advantage of the large screens that are available on devices like tablets

Section 3: The News Reader app

You’ll learn how to develop a News Reader app that displays current news to the user. Along the way, you’ll learn:

  • how to read an RSS feed from the Internet, save that data in a file, and display it on the user interface
  • how to use a service to download data for an app even when the app isn’t running
  • how to notify a user that new data is available even when the app isn’t the current app
  • how to respond to actions that are broadcast by the Android operating system or by other apps

Section 4: The Task List app

You’ll learn how develop a Task List app that stores one or more to-do lists. Along the way, you’ll learn:

  • how to create a database and use it to store data
  • how to use tabs and a custom adapter to display data on the user interface
  • how to use a content provider to allow other apps to work with the same data as this app
  • how to create an app widget that can display some of this app’s data on a device’s Home screen

Section 5: Advanced Android skills

You’ll learn some advanced skills for developing and deploying apps including:

  • how to create a Run Tracker app that tracks the location of a device on a Google Map
  • how to deploy apps to the Google Play store

Who this book is for

This book is for anyone who wants to learn professional skills for developing Android apps. The only prerequisite is a basic understanding of Java, roughly equivalent to chapters 1 through 18 of Murach's Beginning Java with NetBeans or Murach's Beginning Java with Eclipse. Once you have those Java skills, our Android book will work for you, even if you have absolutely no experience developing mobile apps.

What software you need

You can download all of the software that you need for this book for free from the Internet:

  • the Java SDK (Software Development Kit)
  • Android Studio, which includes the Android SDK

Appendixes A, B, and C show how to install and configure this software on Windows, Mac OS X, and Linux.

What hardware we recommend

If necessary, you can use an emulator to run and test Android apps; this book shows you how. Unfortunately, emulators tend to run extremely slowly on most computers. As a result, we recommend using an actual Android device such as a smartphone or tablet whenever possible.

What software this book supports

What version of Android this book supports

Over 95% of all Android devices use Android 4.0 (API 15) or later, and this book reflects that. The only app that won’t work with Android 4.0 is the News Reader app, which is designed to work with Android 4.1 (API 16) and later.

At the time this book was written, the most recent release was Android 6.0 (API 23). But since Android is backwards-compatible, all of the apps will continue to work under subsequent releases, too.

What IDE this book supports

This book shows how to use Android Studio to code, test, and debug apps. Although there are other IDEs for working with Android, today Android Studio is the official IDE for Android development. It’s also available for free, and it runs on all operating systems.

The perfect companion book

As you read our Android book, you may discover that your Java skills aren’t as strong as they ought to be. In that case, we recommend one of our Java books.

Murach's Beginning Java (there’s one edition for Eclipse and one for NetBeans) is designed for programming novices. It moves at the right pace for beginners and gives you a full set of core Java skills.

But if Java isn’t your first language, you may prefer Murach’s Java Programming (4th Edition). It moves at a faster pace, and goes into more depth and breadth, especially about developing desktop applications.

No matter which you choose, these books will get you up-to-speed with the core Java skills that you need for developing Android apps.

What people say about this book

“As someone who first learnt Android programming from a confusing jumble of resources strewn across the Internet - from Google's tutorials to StackOverflow questions to any number of random blog posts that search threw up - I can honestly say I wish I had read this book first, because it would have saved me an awful amount of time and confusion.
     “The book takes the reader along a gentle basics-to-advanced learning path that quite accurately addresses at every step what a new developer should learn next, both on the front end and back end.”
- Karthik Shiraly, CodeRanch

“After going through the entire book, I feel this really gives people an end-to-end coverage of getting into android application making. It is geared towards folks looking to get a handle on a complex topic; walking through the chapters it really presents material in a great fashion. The exercise and homework questions are on point, the writing clear, and the example applications germane and useful. A perfect book for someone who is stuck on the hurdle of ‘where do I start.’”
- Jeremy Johnson, Dream in Code

“Taking into consideration the well-structured content, clear and concise writing style, practical code samples and exercises, I think this book serves as an excellent learning tool to those who are getting their feet wet in the world of Android programming or who just want to update their core Android programming skills.”
- Jason Ong, ASPNETWorld

“Want to get into Android programming fast and seamlessly? This book is all you need to create an application from scratch and publish it successfully to Google Play Market.”
- Igor Rolinsky, Chicago Java Users Group

To view the table of contents for this book in a PDF: Table of Contents

Click on any chapter title to display or hide its content.

Section 1 Get started fast with Android

Chapter 1 An introduction to Android and Android Studio

An overview of Android

Types of devices

Types of apps

A brief history

Versions

System architecture

How apps are compiled and run

An introduction to Android Studio

How to work with the Welcome page

How to open an existing project

How to view the user interface for an app

How to view the code for an app

How to run an app on a physical device

How to run an app on an emulator

The user interface

Chapter 2 How to start your first Android app

The Tip Calculator app

The user interface

How to create a new project

How to develop the user interface

How to work with a layout

How to add widgets to a layout

How to set the display text

How to work with resource files

How to set properties

Common properties

The XML for the user interface

Chapter 3 How to finish your first Android app

How to write the Java code

How to work with an activity

How to remove the v7 appcompat support library

How to get references to widgets

How to handle the EditorAction event

How to get and set the text for widgets

The lifecycle of an activity

How to save and restore values

The Java code for the app

More skills for finishing an app

How to work with the Gradle build script

How to work with dependencies

How to work with the Android manifest

How to set the launcher icon for an app

How to use the documentation for the Android API

Chapter 4 How to test and debug an Android app

Basic skills for testing and debugging

Typical test phases

How to check the layout

How to handle runtime errors

How to trace code execution

How to use LogCat

How to use toasts

How to use the debugger

How to set and remove breakpoints

How to step through code

How to inspect variables

How to inspect the stack trace

How to create emulators

How to create an emulator for a tablet

How to create an emulator for a phone with a hard keyboard and DPad

Section 2 Essential Android skills

Chapter 5 How to work with layouts and widgets

An introduction to layouts and widgets

A summary of layouts

A summary of widgets

The View hierarchy

How to work with layouts

How to use a linear layout

How to use a table layout

How to use a frame layout

How to nest layouts

How to provide a landscape layout

How to work with widgets

How to use editable text views

How to use check boxes

How to use radio buttons

How to use spinners

How to use seek bars

How to display images

How to show and hide widgets

How to add scroll bars

How to display web content

Chapter 6 How to handle events

A summary of listeners

High-level events

Low-level events

Four techniques for handling events

How to use the current class as the listener

How to use a named class as the listener

How to use an anonymous class as the listener

How to use an anonymous inner class as the listener

When to use each technique

How to handle high-level events

How to handle events for check boxes and radio buttons

How to handle events for radio groups

How to handle events for spinners

How to handle events for seek bars

How to handle low-level events

How to handle Key events

How to handle Touch events

The Tip Calculator app

The user interface

The Java code for the activity

Chapter 7  How to work with themes and styles

An introduction to themes and styles

Three common themes

How to supply different themes for different APIs

How to convert an existing project to the AppCompat theme

How to work with styles

How to define a style

How to apply a style

How to create a style sheet

How to work with themes

How to modify a built-in theme

How to modify the AppCompat theme

How to modify a theme depending on the API

How to modify the text appearance for a theme

A summary of built-in themes

How to apply themes

How to work with colors

How to define colors

How to apply colors

Chapter 8  How to work with menus and preferences

How to work with menus

An introduction to menus

How to define a menu

How to display an options menu

How to handle option menu events

How to start a new activity

How to work with preferences

An introduction to preferences

How to define preferences

How to display preferences

How to get preferences

How to use preferences

More skills for working with preferences

How to group preferences

How to enable and disable preferences

How to use Java to work with preferences

Chapter 9 How to work with fragments

An introduction to fragments

Single-pane and multi-pane layouts

The lifecycle methods of a fragment

How to use single-pane layouts for small screens

How to create the layout for a fragment

How to create the class for a fragment

How to display a fragment in an activity

How to create a preference fragment

How to display a preference fragment in an activity

How to use multi-pane layouts for large screens

How to add multiple fragments to a layout

How to detect screen width

How to control the soft keyboard

Other skills for working with fragments

How to get a reference to a fragment

How to replace one fragment with another

Section 3 The News Reader app

Chapter 10 How to work with threads, files, adapters, and intents

An introduction to the News Reader app

The user interface

The XML for an RSS feed

How to work with threads

How threads work

How to execute asynchronous tasks

How to execute timed tasks

How to update the UI thread

How to work with files

How to download a file from the Internet

How to parse an XML file

The RSSFeedHandler class

The RSSFeed class

The RSSItem class

How to work with adapters

How to create the layout for a list view

How to use an adapter to display data in a list view

How to handle events for an adapter

How to work with intents

How to pass data between activities

How to view a URL in a web browser

How to dial or call a phone number

The News Reader app

The activity_items layout

The ItemsActivity class

The FileIO class

The activity_item layout

The ItemActivity class

Chapter 11 How to work with services and notifications

How to work with the Application object

How to define the Application object

How to register the Application object

How to use the Application object

How to work with services

The lifecycle of a service

How to create a service

How to register a service

How to start and stop a service

How to use threads with services

How to test a service

How to view all services

How to work with notifications

How notifications work

How to create a pending intent

How to create a notification

How to work with system services

How to display or remove a notification

How to check if a network connection is available

The News Reader app

The NewsReaderService class

The ItemsActivity class

The FileIO class

Chapter 12 How to work with broadcast receivers

How to work with system broadcasts

A summary of the system broadcasts

How to code a receiver for the boot completed broadcast

How to code a receiver for the connectivity changed broadcast

How to work with custom broadcasts

How to create and send a custom broadcast

How to code a receiver for a custom broadcast

Section 4 The Task List app

Chapter 13 How to work with SQLite databases

An introduction to databases

The user interface for the Task List app

An introduction to SQLite

An introduction to the Task List database

The business objects for the Task List app

How to create a database class

How to define the constants for a database

How to define the SQL statements that create a database

How to create or upgrade a database

How to open and close a database connection

How to add public methods to a database class

How to retrieve multiple rows from a table

How to retrieve a single row from a table

How to get data from a cursor

How to insert, update, and delete rows

How to test the database

How to test the database class

How to clear test data from a device

How to work with the database file

How to use DB Browser for SQLite

Chapter 14 How to work with tabs and custom adapters

How to use tabs

How to add the TabManager class to your project

The layout for an activity that displays tabs

The class for an activity that displays tabs

The class for a fragment that displays tab content

How to use a custom adapter

A layout for a list view item

A class that extends the layout for a list view item

A class for a custom adapter

A class for a fragment that uses a custom adapter

The Task List app

The user interface

The activity_task_list menu

The TaskListActivity class

The activity_add_edit and spinner_list layout

The activity_add_edit menu

The AddEditActivity class

Chapter 15 How to work with content providers

An introduction to content providers

URIs for content providers

MIME types for content providers

How to add supporting methods to the database class

How to create a content provider

How to start a content provider class

How to provide for querying

How to provide for inserting rows

How to provide for updating rows

How to provide for deleting rows

How to register a content provider

How to use a content provider

How to use a custom content provider

How to use a built-in content provider

How to work with a dialog box

How to import the dialog class and interface

How to build and show the dialog box

The Task History app

The user interface

The XML for the layouts

The Java code for the activity

Chapter 16 How to work with app widgets

An introduction to app widgets

A Home screen that has app widgets

How to remove app widgets

How to add app widgets

How to create app widgets

How to create the layout

How to modify the database class

How to create the provider class

How to configure an app widget

How to register an app widget

How to test an app widget

Section 5 Advanced Android skills

Chapter 17 How to deploy an app

An introduction to distribution and monetization

How distribution works

How monetization works

How to create a release build

How to prepare an app for release

How to create the signed APK file

How to distribute directly to the user

How to distribute via a website

How distribute via email

How to publish on Google Play

How to set up a publisher account

How to use the Developer Console to publish an app

How to view the listing for an app

Chapter 18 How to work with locations and maps

An introduction to locations and maps

The user interface for the Run Tracker app

An introduction to determining location

An introduction to maps

An introduction to the Google Maps Android API

How to configure the Google Maps Android API v2

How to create a new Google Maps project

How to add Google Play services to an existing project

How to get a Google Maps API key

How to set permissions and features

How to work with locations

How to connect to Google Play services

How to get the current location

How to handle a failed connection

How to get location updates

How to make sure GPS is enabled

How to work with Google Maps

How to add a map fragment to a layout

How to display a map

How to zoom in on a location

How to add markers

How to add lines

The Run Tracker app

The activity_run_map layout

The RunMapActivity class

The RunTrackerService class

Sample chapters

Chapter 1: An introduction to Android and Android Studio

To show you how well this book works, this free chapter introduces you to the concepts and terms that you need for developing Android apps. Then, it shows how to use Android Studio to work with an existing project. This gives you hands-on experience working with the book apps that you can download below.

Chapter 1 PDF (1.7Mb) Download Now

Android Studio Update for 2017

Since Murach’s Android Programming (2nd Edition) was published in 2015, there have been some significant improvements to Android Studio that impact chapters 1 and 2. Most of this document attempts to show you how to take advantage of these improvements. We recommend reading it after you’ve read pages 1-15 of chapter 1.

Android Studio Update for 2017 PDF (1.7Mb) Download Now

Book apps and exercises

This download includes:

  • The source code for the apps that are presented in the book
  • The starting source code for the exercises in the book
  • The solutions to the exercises so you can check your work

Appendixes A, B, and C show how to install this source code on Windows, Mac OS X, and Linux.

Exe file for Windows (15.1Mb) Download Now

Zip file for any system (14.9Mb) Download Now

Have there been recent changes to Android Studio?

Since Murach’s Android Programming (2nd Edition) was published in 2015, there have been some significant improvements to Android Studio that affect chapters 1 and 2. So we’ve created a FREE PDF that shows you how to take advantage of these improvements, and we recommend you read it after reading pages 1-15 of chapter 1. You can download it here or from the FREE Downloads tab. 

When I create a new project, it uses the ConstraintLayout, not the RelativeLayout described in chapter 2. How do you get the ConstraintLayout to work for the Tip Calculator app?

Android Studio 2.3 and later use the ConstraintLayout as the default layout for a new project and provide integrated tools for working with this layout. The following document describes how to use this layout to create the user interface for the Tip Calculator app:
Android Studio Update for 2017

When I run the News Reader app from chapter 10, it crashes. How can I fix this?

The RSS feed from the CNN website has changed significantly since this book was published. In particular, the title element is often empty, which causes the description to be stored in the title field of the RSSItem object. Also, many items no longer have a pubDate element that stores the publication date. This missing publication date causes the app to crash. You can prevent the app from crashing by modifying the getPubDateFormatted method of the RSSItem class to handle a null publication date like this:

public String getPubDateFormatted() {
    try {
        if (pubDate != null) {
            Date date = dateInFormat.parse(pubDate.trim());
            String pubDateFormatted = dateOutFormat.format(date);
            return pubDateFormatted;
        }
        else {
            return "No date in RSS feed";
        }

    }
    catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

However, a better solution is to modify the RSSFeedHandler and RSSItem classes so that they do a better job of parsing the RSS feed. New and improved versions of these classes are now included in the download for this book here:

\book_apps\ch10_NewsReader_Fixed

These classes substitute a truncated description for the title if the title is missing. In addition, they parse a publication date from the URL for the original link to the item. This publication date no longer includes a time component, but it works.

If you want, you can fix the News Reader apps for the exercises and other chapters by using the code for the new RSSFeedHandler and RSSItem classes instead of the old code that’s described in the book.

To keep the News Reader apps for chapters 11 and 12 working, the download for this book now uses the fixed RSSFeedHandler and RSSItem classes for these apps. Similarly, it uses these fixed classes for all exercise starts and solutions that are based on the News Reader app.

When I run the Run Tracker app from chapter 18, it crashes when I click on the Start button. How can I fix this?

Android (API 23) and later request permissions at runtime when the user needs them instead of requesting them when they install the app. Since the Run Tracker app presented in Murach’s Android Programming does not request these permissions at runtime, it crashes on API 23 and later when you click the Start button of the Stopwatch activity. To fix this issue, you can add the following code to the StopwatchActivity class:

// add this constant to the StopwatchActivity class
private final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;

// add this code to the onStart method of the StopwatchActivity class
if (Build.VERSION.SDK_INT > 22) {
    if (checkSelfPermission(
            Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
    }
}

For more details about how this code works, you can view the last figure of the following document:
Android Studio Update for 2017

To view the corrections for this book in a PDF, just click on this link: View the corrections

Then, if you find any other errors, please email us so we can correct them in the next printing of the book. Thank you!

Rob Spoor

Saturday, 20 February 2016

Murach's Android Programming is a good introduction into Android programming.

Disclosure: I received a copy of this book from the publisher in exchange for writing this review on behalf of CodeRanch.

To leave a review, please log in to your account.     Log In Here

Our Ironclad Guarantee

You must be satisfied. Try our books for 60 days. They must be the best you've ever used or send them back for a prompt refund. No questions asked!

Contact Murach Books

For orders and customer service:

1-800-221-5528

Weekdays, 8 to 4 Pacific Time

College Instructors

If you're a college instructor who would like to consider a book for a course, please visit our website for instructors to learn how to get a complimentary review copy and the full set of instructional materials.