Chapters

Hide chapters

Android Apprentice

Fourth Edition · Android 11 · Kotlin 1.4 · Android Studio 4.1

Section II: Building a List App

Section 2: 7 chapters
Show chapters Hide chapters

Section III: Creating Map-Based Apps

Section 3: 7 chapters
Show chapters Hide chapters

24. Podcast Subscriptions, Part One
Written by Fuad Kamal

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

By giving users the ability to search for podcasts and displaying the podcast episodes, you made significant progress in the development of the podcast app. In this section, you’ll add the ability to subscribe to favorite podcasts.

Over the next two chapters, you’ll add the following features to the app:

  1. Storing the podcast details and episode lists locally for quick access (this chapter).
  2. Displaying the list of subscribed podcasts by default (this chapter).
  3. Notifying the user when new episodes are available (next chapter).

You’ll cover several new topics throughout these two chapters including:

  1. Using Room to store multiple related database tables.
  2. Using JobScheduler services to check for new episodes periodically.
  3. Using local notifications to alert users when new episodes are available.

Getting started

If you’re following along with your own project, open it and keep using it with this chapter. If not, don’t worry. Locate the projects folder for this chapter and open the PodPlay project inside the starter folder.

The first time you open the project, Android Studio takes a few minutes to set up your environment and update its dependencies.

Saving podcasts

The first new feature you’ll implement is the ability to track podcast subscriptions. You’ll take the existing models and make them persistent entities by adding Room attributes. The database will only contain podcasts to which the user subscribes.

Adding Room support

Before getting into the code, you need to bring in the Room libraries.

Annotating the models

Your first task is to properly annotate the existing models so that Room knows how to store the data. Start by getting the Podcast class into shape.

Data access object

Before you can define the main Room database object, you need to create the DAO to read and write to the database. This is where you define all of the SQL statements for the basic database operations. You’ll add additional methods later, but for now, all you need is the ability to save and load podcasts and their corresponding episodes.

Define the Room database

All that’s left to do is define the Room database object and have it instantiate the PodcastDao object.

Room type converters

Although Room can’t handle complex types directly, it provides a concept known as TypeConverters that let you define how to convert them to-and-from basic types. This is the perfect solution for the Date properties.

Room object references

Now back to the episodes list in the Podcast model. Since Room does not support defining object references in Entity classes, you need to tell it to ignore the episodes property.

Update the podcast repo

The podcast repo currently uses only the RssFeedService to retrieve podcast data. One benefit of using the repository pattern is that a single repository can access data from multiple sources or services.

Updating the view model

One more step is needed before you can connect the subscribe menu item. Since the view only talks to the view model, you need to update the podcast view model to use the new repository methods.

Connecting the subscribe menu item

Everything is now in place to hook up the subscribe menu item on the podcast detail screen.

Displaying subscribed podcasts

That completes the code to subscribe to a podcast. Of course, subscribing to a podcast isn’t useful if you don’t let the user see their subscriptions!

Key Points

In this chapter:

Where to go from here?

Good job! You made it through the first part of podcast subscriptions. Take a breather, and pick up with part two when you’re ready to finish!

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now