Version First Edition
Platform Android 9
Language Kotlin 1.3
Editor Android Studio 3.2

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 taking your app to the next level!

This book will introduce you to a number of architectures, including Model View Controller, Model View Presenter, Model View Intent, Model-View-ViewModel and VIPER. You’ll learn theory, explore samples that you will refactor and learn the fundamentals of testing.

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.

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.


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.


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.


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.


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.


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.

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.


With theory in tow, you’ll then refactor WeWatch to the MVP pattern step-by-step.


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.


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.


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.


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.

Here, you’ll learn all of the theory behind each of the layers of the VIPER architecture pattern: View, Interactor, Presenter, Entity and Router.


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.


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.


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.


Here, you’ll rewrite WeWatch using the MVI pattern and the popular RxJava framework for your Observable callbacks.


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.


Meet the team


Who is this book 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.

Concepts covered in this book

  • 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


Version history

First Edition · Android 9, Kotlin 1.3, Android Studio 3.2

v1.0 · Apr 28 2019 · Yun Cheng & Aldo Olivares
See book details

Advanced Android App Architecture

By Yun Cheng & Aldo Olivares

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!

Read for Free with the Pro subscription* * 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.
See buying options
Hide buying options

All videos. All books.
One low price.

A subscription is the best way to learn and master mobile development — plans start at just $19.99/month!

Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.