Android & Kotlin

Advanced Android App Architecture

In Advanced Android App Architectures, you'll find a diverse and hands-on approach to architecting your apps on Android. Learn how to build scaleable and maintainable architectures in Android and Kotlin, including MVC, MVP, MVI, MVVM and VIPER! By Yun Cheng & Aldo Olivares.

Read for Free with the Personal Plan* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.

4 (1) · 1 Review

Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is for intermediate Android developers who already know the basics of Android and Kotlin development but want to learn how best to organize code for scale.UI development but want to learn coroutine API in order to simplify and optimise their code.

Covered concepts

  • Model View Controller Theory
  • Testing
  • Android Architecture Components
  • Dependency Injection
  • Model View Presenter Theory
  • Model View ViewModel Theory
  • VIPER Theory
  • Model View Intent Theory
  • Debugging

In Advanced Android App Architectures, you’ll find a diverse and hands-on approach to architecting your apps on Android. Android development can be fun; however, scaling an app can have its fair share of problems.

In this book, you’ll learn why a conversation on architecture is the first important step to...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Building a Foundation

This section introduces you to topics that will serve as a foundation for your understanding of the UI architecture patterns. You’ll get introduced to the sample project, an app named WeWatch, that allows users to keep track of movies to watch. You’ll also learn concepts that aid architecture, including Android Architecture Components and dependency injection.

1
Toggle description
This chapter explains what this book is about and its intended audience. By reading this chapter, you’ll gain a better understanding of why apps need good architecture. You’ll also get an introduction to the sample app that you’ll be building throughout this book.
2
Toggle description
The sample project starts off written in the Model View Controller pattern, with the Android Activity serving as both the View and the Controller. In this chapter, you’ll learn the history of the MVC pattern as applied to Android, and you’ll learn why this UI architecture pattern fails to meet two primary standards for good code: separation of concerns and unit testability.
3
Toggle description
Here, you’ll get a quick review on writing unit tests with JUnit, and you’ll learn why the MVC pattern results in poor unit testability of code.
4
Toggle description
In this chapter, you’ll get an overview of the Android Architecture Components and go into detail on the libraries used in the sample project at various points in the book: Room, ViewModel, LiveData and Data Binding.
5
Toggle description
An important concept in writing testable code is using dependency injection to inject mock objects into code. Here, you’ll learn the theory behind dependency injection and create a practical sample project using Dagger 2, a popular dependency injection framework for both Java and Android.
Toggle description
In this chapter, you’ll get an overview of RxJava and go into detail on how the library is used in the sample project at various points in the book.

Section II: Fundamental UI Architectures

In this section, you’ll rewrite WeWatch three different ways, first using MVP, then using MVVM with data binding, and finally using MVVM with Android Architecture Components. Though a user of the app won’t be able to see any difference after each of these changes, you as a developer will see how they solve some of the problems of the original WeWatch app written in MVC.

Toggle description
The first architecture pattern you’ll learn is Model View Presenter. Here, you’ll learn the theory behind pulling presentation logic out of the Android Activity and why it results in a significant improvement over the MVC pattern in terms of separation of concerns and testability of code.
Toggle description
With theory in tow, you’ll then refactor WeWatch to the MVP pattern step-by-step.
Toggle description
Now that you’ve refactored the app to MVP, you can write unit tests on the logic that previously was untestable when it was in the MVC pattern.
Toggle description
The next architecture pattern you’ll learn is Model-View-ViewModel, a pattern which centers on exposing a stream of events to Views. Architecting your app this way helps you write loosely coupled and easily testable code.
Toggle description
In this chapter, you’ll refactor WeWatch to the MVVM pattern using the Data Binding library from Android Architecture Components.
In this chapter, you’ll again refactor WeWatch to the MVVM pattern, this time using a combination of the ViewModel and LiveData libraries from Android Architecture Components.
Toggle description
Having completed the refactoring of the app to MVVM, you’ll write unit tests on the ViewModel to ensure it behaves as expected.

Section III: VIPER & MVI

In this section, you’ll rewrite WeWatch two different ways, first using VIPER and then using MVI. VIPER is similar to the MVP architecture but adds another two layers of abstraction to provide the highest level of modularity. On the other hand, MVI follows a different approach by using reactive programming principles with powerful libraries such as RxJava.

Toggle description
Here, you’ll learn all of the theory behind each of the layers of the VIPER architecture pattern: View, Interactor, Presenter, Entity and Router.
Toggle description
Now that you know how VIPER works, you’ll apply your new knowledge by rewriting WeWatch using this new pattern. You’ll also learn how to use Cicerone to create your Routers to navigate through the Views of your app.
Toggle description
In this chapter, you’ll learn how to test your VIPER implementation by creating unit tests for each of your Presenters and using Mockito to mock your Views and Interactors.
Toggle description
MVI is a special architecture pattern that relies on reactive programming to react to user actions and render your Views. You’ll learn how to create Intents, Views and Models that represent a state of your app.
Toggle description
Here, you’ll rewrite WeWatch using the MVI pattern and the popular RxJava framework for your Observable callbacks.
Toggle description
In this chapter, you’ll learn how to debug your MVI implementation using RxJava operators — such as onNext() — to see which was the last Intent emitted and the last View rendered.

Authors

Yun Cheng
Aldo Olivares

Contributors

Yun Cheng

Author

Aldo Olivares

Author

Nick Bonatsakis

Tech Editor

Matei Suica

Tech Editor

Vijay Sharma

Final Pass Editor

Over 300 content creators. Join our team.