Android Programming Tutorials

Developing Mobile Apps for the Android Platform

Interested in training from the author of these tutorials? See the upcoming Android training course in Maryland, co-sponsored by Johns Hopkins Engineering for Professionals. Or, contact hall@coreservlets.com for info on customized Android courses at your location.


Following is a series of tutorials on Android programming. Since each section includes exercises and exercise solutions, this can also be viewed as a self-paced Android training course. Click on a section below to expand its content.

Overview of the Android Tutorials

Although Web applications are important and widely used, there are several reasons why native applications are sometimes preferable for mobile apps.

  • You can use graphics and UI controls that are not available in browsers.
  • You can customize the apps for small screen sizes.
  • You can use resources (location, address book, phone, network, local database) that are unavailable in Web-based applications.

Android is the preferred platform for building corporate apps since you can install Android apps from your company Web site, rather than submitting them to the Apple App Store as required for the iPhone (unless all employees jailbreak their phones).

Click on a topic below to get the detailed tutorial for that topic, download the section's source code as an Eclipse project, see exercises, get the source code for the exercise solutions, or to simply run the sample apps from that section. Practicing is the key to learning, so I strongly recommend that you try out a few of the exercises in each section before you peek at the solutions.

These tutorials are derived from Marty Hall's world-renowned live Android training courses. Customized courses on Android are usually taught on-site at customer locations, but servlet, JSP, Ajax, GWT, JSF 2.0, Spring, Hibernate, RESTful Web Services, Android, and Java 6 training courses at public venues are periodically scheduled for people with too few developers for an onsite course. For descriptions of the various other courses that are available, please see the Java EE and Ajax training course page. To inquire about a customized training course at your location, please contact Marty at hall@coreservlets.com.

If you find these free tutorials helpful, we would appreciate it if you would link to us. Send corrections or feedback on any tutorial to hall@coreservlets.com.

Android Programming: Introduction and Overview

This section gives a high-level introduction to developing for the Android platform.

  • This tutorial section in PDF.
  • Topics covered:
    • Motivation
      • Web Apps vs. Mobile Apps
      • iPhone Apps vs. Android Apps
    • Books and references
  • Exercises to reinforce the concepts in this section. In general, I strongly recommend that you try out at least a few of the exercises before moving on to later sections, but in this case (since we haven't covered how to get started yet), calling these "exercises" is a bit of an exaggeration.

Android Programming: Getting Started

This section gets you started with the bare-bones basics of Android programming. It covers installing and configuring the necessary software and how to make and test very simple applications.

Android Programming Basics

This section shows you the basic style of Android programming, and illustrates three common variations on the theme. This section assumes that you have already installed and configured the necessary software (as described in the previous tutorial section), and that you know how to make and test applications.

Widget Event Handling

This section shows how to write code that responds to button clicks and other GUI events. It compares and contrasts five standard ways of handling events, giving pros and cons of each approach.

Widgets I: Buttons and Similar Clickable Widgets

This is the first of several sections that give examples of basic Widgets. Here, we look at Button, ImageButton, RadioButton, RadioGroup, CheckBox, and ToggleButton.

Widgets II: Spinners (Combo Boxes)

This section covers the Spinner widget, which is Android-speak for a combo box (a drop down list of choices). It also explains how to switch from one Activity to another at run time.

Layouts: Organizing the Screen

This section covers the core Android Layout types and the design strategy of nesting one Layout inside another. It also covers defining colors in XML resource files, and very briefly introduces localization (which will be covered in detail later).

Coding Style: The Official Android Conventions

This section discusses the official Android code-style conventions.

  • This tutorial section in PDF.
  • Topics covered:
    • Why follow conventions?
    • Valuable conventions
      • Ones that are widely considered good practice for any Java project (based on general Java industry consensus)
    • Tolerable conventions
      • Ones that do no harm, but are of questionable value (in Marty’s highly subjective opinion)
    • Dubious conventions
      • Ones that we would have been better off without (in Marty’s highly subjective opinion)
  • Eclipse preferences file. You can import this into Eclipse to get my preference file, which enforces the indentation, brace style, and @Override usage from the official Android coding conventions.

Intents Part I: Invoking Activities by Class Name

This is the first of three relatively short sections on Intents, Intent Filters, and switching from one Activity to another. In this part, we invoke the new Activity by using the specific class name.

Intents Part II: Invoking Activities with URIs

This is the second of three relatively short sections on Intents, Intent Filters, and switching from one Activity to another. In this part, we invoke the new Activity indirectly by using a URI.

Intents Part III: Invoking Activities with Tabbed Windows

This is the third of three relatively short sections on Intents, Intent Filters, and switching from one Activity to another. In this part, we invoke the new Activity by clicking on a tab in a tabbed window.

Localization and Resources

This topic covers how to make applications that adapt to changes in the user's language, screen orientation, display density, and so forth. It also reviews some of the most common resource types.

Handling Screen Rotations and App Restarts

When the user rotates the phone from portrait to horizontal mode, the app is shut down and then restarted. Apps are restarted in a few other situations as well. This topics explains how to preserve data in those situations.

Networking I: General Techniques

This section covers the basics of Android network programming as well as some refreshers on String formatting and parsing. Techniques specific to HTTP and JSON are covered in the section after this one.

Networking II: HTTP and JSON Techniques

This section covers networking techniques specific to HTTP servers and JSON data. The basics of Android network programming are covered in the previous section.

Multithreaded Programming Part I: General Techniques

This section covers the basics of multithreaded programming as used generally in the Java programming language. The next section covers the aspects that are specific to Android. If you are already comfortable with ExecutorService, Runnable, and synchronization in "normal" Java, skip this section and move on to the next one.

  • This tutorial section in PDF.
  • Topics covered:
    • Why threads?
    • Basic approach
      • Make a task list with Executors.newFixedThreadPool
      • Add tasks to list with taskList.execute(someRunnable)
    • Three variations on the theme
      • Separate classes that implement Runnable
      • Main Activity implements Runnable
      • Inner classes that implement Runnable
    • Related topics
      • Race conditions and synchronization
      • Helpful Thread-related methods
      • Advanced topics in concurrency
  • Multithreading.zip. Sample project used in the two multithreaded programming sections, bundled as an Eclipse project.
  • Exercises to reinforce the concepts in this section.

Multithreaded Programming Part II: Android-Specific Techniques

This section covers aspects of multithreaded programming that are specific to Android. It assumes you are already comfortable with general Java threading as discussed in the previous section.

Upcoming Topics

Several more sections coming soon. I plan to add two more sections before the end of August. After that, I will be tied up for a few months, then plan to resume adding topics in the middle of November. Topics on my queue to cover include styles/themes, 2D graphics, location handling, Map components, embedding WebKit, playing audio and video, more widgets (menus, list views, fancy textfields), SMS messaging, local databases with SQLite, services, details on the Android Manifest file, and many more. If you have strong opinions on which topics should come next, or if you have suggestions or corrections on any of the existing topics, please email me at hall@coreservlets.com.

Source Code

Source code for all examples in this tutorial as well as the exercise solutions can be downloaded from the Android sample code repository. Code is free for completely unrestricted use. Each section above also has direct links to the code used in that section.

PowerPoint Files for University Faculty

The PDF files in this tutorial contain the complete text of the original PowerPoint files, so if your goal is learning this technology, just stick with this tutorial. However, as a service to instructors teaching full-semester courses at accredited universities, coreservlets.com will release the original PowerPoint files for free. Please see the instructor materials page for details.

More Information

Java

Servlets & JSP

JSF
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts