/android-architecture

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

Apache License 2.0Apache-2.0

Android Architecture Blueprints

Android Architecture Blueprints

The Android framework provides a lot of flexibility in deciding how to organize and architect an Android app. While this freedom is very valuable, it can also lead to apps with large classes, inconsistent naming schemes, as well as mismatching or missing architectures. These types of issues can make testing, maintaining and extending your apps difficult.

The Android Architecture Blueprints project demonstrates strategies to help solve or avoid these common problems. This project implements the same app using different architectural concepts and tools.

You can use the samples in this project as a learning reference, or as a starting point for creating your own apps. The focus of this project is on demonstrating how to structure your code, design your architecture, and the eventual impact of adopting these patterns on testing and maintaining your app. You can use the techniques demonstrated here in many different ways to build apps. Your own particular priorities will impact how you implement the concepts in these projects, so you should not consider these samples to be canonical examples. To ensure the focus is kept on the aims described above, the app uses a simple UI.

Explore the samples

This project hosts each sample app in separate repository branches. For more information, see the README.md file in each branch.

Stable samples - Java

Sample Description
todo‑mvp Demonstrates a basic Model‑View‑Presenter (MVP) architecture and provides a foundation on which the other samples are built. This sample also acts as a reference point for comparing and contrasting the other samples in this project.
todo‑mvp‑clean Uses concepts from Clean Architecture.
todo‑mvp‑dagger Uses Dagger 2 to add support for dependency injection.
todo‑mvp‑rxjava Uses RxJava 2 to implement concurrency, and abstract the data layer.
todo‑mvvm‑databinding Based on the todo-databinding sample, this version incorporates the Model‑View‑ViewModel pattern.
todo‑mvvm‑live Uses ViewModels and LiveData from Architecture Components and the Data Binding library with an MVVM architecture.

Stable samples - Kotlin

Sample Description
todo-mvp-kotlin Conversion of todo-mvp to Kotlin.
todo-mvvm-live-kotlin Conversion of todo-mvvm-live to Kotlin.

External samples

External samples are variants that may not be in sync with the rest of the branches in this repository.

Sample Description
todo‑mvp‑fragmentless Uses View objects instead of Fragment objects.
todo‑mvp‑conductor Uses the Conductor framework to refactor the app to use a single Activity architecture.
todo‑mvi-rxjava Adapts the Model-View-Intent pattern to Android to create a fully reactive architecture.
todo‑mvp-kotlin-coroutines Replaces the asynchronous operations with Kotlin's coroutines.

Deprecated samples

These samples are no longer being maintained, but their implementation is still valid.

Sample Description
todo‑mvp‑loaders Fetches data using the Loaders API.
todo‑databinding Replaced by todo‑mvvm‑databinding
todo‑mvp‑contentproviders Based on the todo-mvp-loaders sample, this version fetches data using the Loaders API, and also makes use of content providers.

Samples in progress

Sample Description
dev‑todo‑mvvm‑rxjava Based on the todo-rxjava sample, this version incorporates the Model‑View‑ViewModel pattern.

For information about planned samples, see "New sample" issues.

Why a to-do app?

The app in this project aims to be simple enough that you can understand it quickly, but complex enough to showcase difficult design decisions and testing scenarios. For more information, see the app's specification.

The following screenshot illustrates the UI of the app:

A screenshot illustratrating the UI of the app

Choose a sample for your app

Each sample includes a dedicated README.md file where you can find related metrics, as well as subjective assessments and observations by contributors. The following factors are worth considering when selecting a particular sample for your app:

  • The size of the app you are developing
  • The size and experience of your team
  • The amount of maintenance that you are expecting to have to do
  • Whether you need a tablet layout
  • Whether you need to support multiple platforms
  • Your preference for the compactness of your codebase

For more information on choosing and comparing samples, see the following page: How to compare samples

Open a sample in Android Studio

To open one of the samples in Android Studio, begin by checking out one of the sample branches, and then open the todoapp/ directory in Android Studio. The following series of steps illustrate how to open the todo‑mvp sample.

Note: The master branch does not compile.

Clone the repository:

git clone git@github.com:googlesamples/android-architecture.git

Checkout the todo-mvp sample:

git checkout todo-mvp 

Note: To review a different sample, replace todo-mvp with the name of sample you want to check out.

Finally open the todoapp/ directory in Android Studio.

Contributors

This project is built by the community, and curated by Google as well as other core maintainers.

License

Copyright 2019 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.