Chapters

Hide chapters

Real-World Android by Tutorials

Second Edition · Android 12 · Kotlin 1.6+ · Android Studio Chipmunk

Section I: Developing Real World Apps

Section 1: 7 chapters
Show chapters Hide chapters

1. Introduction
Written by Ricardo Costeira

Ever since its inception, Android development has been known for being as frustrating as it is fun. Ironically, both the frustration and the fun come from the same place. Developing an Android app involves not only juggling an ever-changing framework, but also handling interesting and challenging design decisions.

The Android framework keeps growing, and it’s not likely to stop anytime soon. Think of the sheer amount of documentation online at the Android Developers site, or even on Kotlin’s own documentation pages. On top of this, time and experience have taught us that new architectures and best practices will keep appearing, giving us new and better ways to do the same things.

This isn’t necessarily bad, though. Android developers have come a long way since the times when having a god Activity was the standard. Over the years, through the effort of an amazing and supporting community, multiple architectures and techniques have surfaced, aiming to improve both app stability and developer quality of life. Even Google has pitched in on this project with their own recommended app architecture.

With such a large, continuously mutating ecosystem, developing even the simplest of features can feel overwhelming for beginners — and, sometimes, even for advanced developers.

For instance, say that you want to get data from a data source and display it. Even if you’ve implemented this in the past, you know Android. Can you be 100% sure that the way you did it back then is still the best way to do it now?

You can’t. And that’s OK! With an ecosystem that changes so frequently, it’s impossible for even the most experienced engineer to be aware of all its quirks and nuances.

Android developers need to know about a wide array of subjects to build apps effectively. That’s where this book comes in.

What Is This Book About?

This book covers a lot of topics. It shows you how to:

  • Build features in a scalable way, covering each architectural layer.
  • Modularize your app, if you ever need to, while touching on dynamic features.
  • Handle animations, styles, themes and other elements of the UI.
  • Make your app more secure.
  • Maintain and care for your app.

It does all of this by showing you practical solutions that lead to the desired results. Yet, the idea here is much more than that. Of course, you can study the implementation details if you want, but that’s not the main point. Instead of reasoning about how to write code, you should instead focus on why you write it that way.

The goal is for you to go beyond the code and understand why you’re writing it in the first place. This book doesn’t simply cover the basics at the problem’s surface or give high-level descriptions of the simplest use cases. Rather, it aims to share with you some of the knowledge that developers acquire over time, while developing real-world apps.

You’ll see how to solve real-world problems following real-world best practices and techniques. Sometimes, these best practices and techniques are general rules of thumb regarding software development and design principles. In other cases, they’re tightly coupled to the tools used to fix the problem. You can only acquire them by either getting your hands dirty with those tools or by having someone point them out for you.

The book focuses not only on why should you do things a specific way, but also on the corresponding advantages, trade-offs and drawbacks of that solution. It makes it clear when a certain decision is not ideal, explaining the reasoning behind discarding a choice or going through with it anyway.

As you go through the content, you might notice that some of it is opinionated; you might even disagree with some of the statements. That’s good! As a developer, it’s only natural for you to question other developers’ decisions. You might even see some problems that others completely missed.

On the other hand, if you agree with everything and don’t see any problems, that’s fine too! What’s important here is for you to go through the roller coaster ride that is Android, with all its ups and downs, just like developers do in the real world.

Who Is This Book for?

This book is useful for developers of all levels. Some of the content assumes prior knowledge of complex topics, like RxJava and Dagger/Hilt, and is more tailored to intermediate or advanced developers. But there’s plenty of content suitable for less-experienced developers as well.

Note: If you need to fill some gaps in your knowledge, www.raywenderlich.com, provides a variety of books to help. If you need to learn Kotlin, Kotlin Apprentice, is the right book for you. With Reactive Programming with Kotlin, you can learn all about RxJava and RxKotlin.

Dependency injection is a fundamental tool for simplifying the architecture of your app and making it more testable and maintainable. If you need to learn more, Dagger by Tutorials, is a must. Finally, good, professional apps must implement different types of tests, from unit tests to end-to-end tests. To learn more about how to do this, Android Test-Driven Development by Tutorials, is the book for you.

As mentioned already, a large part of the book’s focus is around the reasons why developers prefer specific solutions. This usually boils down to software design principles, architectural considerations or tidbits of wisdom acquired through experience. In these cases, everyone can benefit from sharing information.

The Sample Project

Throughout this book, you’ll work on building and improving a sample project called PetSave. PetSave is a pet adoption and fostering app that aggregates and matches animals available to you. It uses the medical history of the pet along with some of your personal information for matching and searching.

Figure 1.1 — PetSave Screen With a List of Animals
Figure 1.1 — PetSave Screen With a List of Animals

When you start, the app will only show a blank screen. Even the screen in the image above doesn’t exist yet. It’ll be up to you to develop the app from the ground up.

The app connects to an external service, which it uses to fetch the animals. This service, Petfinder, is an online, searchable database of animals who need homes. They also have information on shelters and adoption organizations across the United States. Check out their site at https://www.petfinder.com/. Who knows, you might find your new pet. :]

Signing Up for an API Key

Petfinder allows you to access their database, provided that you sign up for one of their API keys. To do so, you first need to go to their site and sign up for an account. After that, head to https://www.petfinder.com/developers/, click the GET AN API KEY button and follow the process from there.

After acquiring an API key and its corresponding secret, you’ll need to set them for each chapter’s starter project. You’ll set them in ApiConstants.kt, which is in the common.data.api package.

Figure 1.2 — Replace Those Two Strings With Your API Key and Secret
Figure 1.2 — Replace Those Two Strings With Your API Key and Secret

If you’re curious about Petfinder’s API, check out its documentation at https://www.petfinder.com/developers/v2/docs/.

Where to Go From Here?

Now that you have an idea of what this book is about and how it’ll unfold, you’re ready to start building PetSave. As you already know, the app is at a very early stage, with very little code written. However, you won’t write any code in the next chapter.

Thinking about a problem, getting familiar with it and planning ahead just enough that you have a solid starting point is always a better option than starting to write code right away and hoping for the best. So in the next chapter, you’ll lay the groundwork to develop a robust and scalable app.

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.
© 2024 Kodeco Inc.