The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

Defining a Model

If we are going to show to-do items in this list, it would help to have some to-do items. That, in turn, means that we need a Java class that represents a to-do item. Such a class is often referred to as a “model” class, so in this chapter, we will create a ToDoModel, where each ToDoModel instance represents one to-do item.

However, we will not just make a simple Java class for this. Instead, we will make one that is immutable. Immutable classes are ones where you can create instances but cannot modify existing instances. For many Java classes, such as our MainActivity, having it be immutable is impossible or undesirable. However, for models, immutability has some benefits, particularly for helping us keep track of the state of the model (e.g., do we need to save it to the database?). Java does not have a way of making classes be immutable — unlike Kotlin, which does — but through Google’s AutoValue library, we can craft a model that, in practice, is immutable.

This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Read Me!

This tutorial assumes that you have learned the use of Google’s AutoValue library from somewhere. That could be:

Step #1: Adding a Stub POJO

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Step #2: Linking to AutoValue

The preview of this section is sleeping in.

Step #3: Adding the Annotation

The preview of this section is sleeping in.

Step #4: Defining a Builder

The preview of this section will not appear here for a while, due to a time machine mishap.

Step #5: Adding Properties

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Step #6: Populating Some Default Properties

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

What We Changed

The preview of this section is in an invisible, microscopic font.