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

Overview

Android Architecture Blueprints v2

Illustration by Virginia Poltrack

Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android apps. In its different branches you'll find the same app (a TODO app) implemented with small differences.

In this branch you'll find:

  • Kotlin Coroutines for background operations.
  • A single-activity architecture, using the Navigation component to manage fragment operations.
  • A presentation layer that contains a fragment (View) and a ViewModel per screen (or feature).
  • Reactive UIs using LiveData observables and Data Binding.
  • A data layer with a repository and two data sources (local using Room and remote) that are queried with one-shot operations (no listeners or data streams).
  • Two product flavors, mock and prod, to ease development and testing (except in the Dagger branch).
  • A collection of unit, integration and e2e tests, including "shared" tests that can be run on emulator/device or Robolectric.

Variations

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

Stable samples - Kotlin

Sample Description
master The base for the rest of the branches.
Uses Kotlin, Architecture Components, coroutines, Data Binding, etc. and uses Room as source of truth, with a reactive UI.
dagger-android
[compare]
A simple Dagger setup that uses dagger-android and removes the two flavors.
usecases
[compare]
Adds a new domain layer that uses UseCases for business logic.

Old samples - Kotlin and Java

Blueprints v1 had a collection of samples that are not maintained anymore, but can still be useful. See all project branches.

Why a to-do app?

A demo illustraating the UI of the 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.

What is it not?

  • A UI/Material Design sample. The interface of the app is deliberately kept simple to focus on architecture. Check out Plaid instead.
  • A complete Jetpack sample covering all libraries. Check out Android Sunflower or the advanced Github Browser Sample instead.
  • A real production app with network access, user authentication, etc. Check out the Google I/O app, Santa Tracker or Tivi for that.

Who is it for?

  • Intermediate developers and beginners looking for a way to structure their app in a testable and maintainable way.
  • Advanced developers looking for quick reference.

Opening 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 root directory in Android Studio. The following series of steps illustrate how to open the usecases sample.

Clone the repository:

git clone [email protected]:googlesamples/android-architecture.git

This step checks out the master branch. If you want to change to a different sample:

git checkout usecases

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

Finally open the android-architecture/ directory in Android Studio.

License

Copyright 2019 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you 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.
Comments
  • New Sample: Model View Intent

    New Sample: Model View Intent

    New sample proposal

    I'd like to create a new sample to illustrate the Model View Intent pattern. Full Android examples for MVI are hard to find. It's a pattern that has seen wide adoption in the Javascript and .NET world. Target audience include, but not limited to:

    • Developers making the pivot from an imperative to declarative style of programming.
    • Developers looking for best-practices in functional or reactive programming on Android.

    Here are some articles/examples explaining the core principles of MVI and unidirectional flow:

    • http://hannesdorfmann.com/android/model-view-intent
    • https://cycle.js.org/model-view-intent.html
    • http://thenewstack.io/developers-need-know-mvi-model-view-intent/

    Proposed stack

    I'm hoping to use specific libraries to achieve this in the cleanest possible way. A requirement with the android-architecture samples is to use accepted industry standard. A few of these libraries are new as of this year, but I believe they still fulfill that requirement. I've taken the time to establish a small 'pedigree' for each.

    The following are battle-tested libraries. Battle tested here means that they have documented use, in production, at major companies with a large user base. Places such as Square, Groupon, Trello, Shopify, etc. One notable exception is RxJava2. RxJava 2 has major community backing, and will see a production release later this month.

    Also, the following all have well-know, senior maintainers with established track records. Below a detailed list with rationale/credentials:

    New sample 
    opened by kanawish 20
  • Migration to Dagger Android/Contributes Injector

    Migration to Dagger Android/Contributes Injector

    This pr updates the Dagger sample to now us modern best practices such as subclassing DaggerApplication as well as the new @ContributesInjector construct.

    opened by digitalbuddha 18
  • New Sample: Using Kotlin coroutines

    New Sample: Using Kotlin coroutines

    I'd like to create a sample that demonstrates the power and elegance of Kotlin coroutines. It will use MVVM, Data Binding and Architecture Components (ViewModel and possibly LiveData). I plan to branch it off dev-todo-mvvm-live-kotlin. The suggested new branch name is dev-todo-mvvm-live-kotlin-coroutines.

    The primary objective is to select and consistently apply a small subset of essential Kotlin coroutine idioms.

    New sample community request 
    opened by alex-chiviliov 12
  • Added strict Null-Ptr checks of context or activity in some fragments

    Added strict Null-Ptr checks of context or activity in some fragments

    Because new version has strict check for null-ptr of context or activity in fragments. It would be nice to have new and early experience with this new gradle feature.

    opened by XinyueZ 11
  • New sample: rxjava2

    New sample: rxjava2

    I was surprised to see the rxjava example still uses rxjava 1. Has there been any work related to an example using rxjava 2 or are there plans on doing this ?

    opened by jonasgeiregat 9
  • [all] adding CircleCI configuration file

    [all] adding CircleCI configuration file

    At the moment there is only TravisCI configuration file. Adding those for CircleCI would be fairly easy to do and Jose said it could be a nice addition to the project. I am willing to do it if welcomed. In the case I need to merge on all projects, do I need to create a PR for each or one would be enough for the merge-master to pass it on the others?

    enhancement 
    opened by oldergod 9
  • Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    opened by shakil807g 8
  • [todo-mvvm] Architecture Components sample

    [todo-mvvm] Architecture Components sample

    I want to integrate the latest architectural components (ViewModel, LiveData, LifeCycleOwner) into the todo-mvvm. Should there be a new branch with the name [todo-mvvm-{newandroidarch/somethingelse}] or should I start editing in this branch only?

    opened by gaurav414u 8
  • Sample using Conductor and a single Activity architecture

    Sample using Conductor and a single Activity architecture

    Hi everyone,

    I decided to try making a sample that only uses a single Activity architecture using the Conductor library.

    I've put the branch up here and I'd really appreciate any feedback!

    It turned out to not be too difficult, the Activities and Fragments became Controllers and everything else stayed the same. I had to do some interesting code around getting the DrawerLayout working and constantly changing the ActionBar to have new stuff in it.

    The main thing left to do is that it broke a few of the Espresso tests and also made most of them super flakey. The problem is that the test no longer knows that it needs to wait while the next Controller loads (I guess Espresso is usually aware of Activity transitions and I no longer have that crutch). I had a look at using IdlingResource to solve this, but I'm not experienced with Conductor or Espresso, I'll keep working on it. Also, the hermetic UI tests of individual Activities will probably never work hermetically since I don't think I can jump into a specific Controller like you can with Activities, you need to navigate there.

    New sample community request 
    opened by grepx 8
  • fix to take care of the order of method calls

    fix to take care of the order of method calls

    Hi,

    Could you please review this ?

    This patch makes the unit test method calls order sensitive.

    I guess the transition from 'true' to 'false' is important for the test. mTasksView).setLoadingIndicator(true); mTasksView).setLoadingIndicator(false);

    opened by sfuku7 8
  • Proposed extension of RxJava usage across all layers of the MVP

    Proposed extension of RxJava usage across all layers of the MVP

    I've built a small example of how we could use RxJava across the View/Presenter bridge. Benefits include the possibility of writing Presenter tests as observable chains, cleaner observable chain building in the presenter (allows for debouncing, more sophisticated UX behavior, etc.)

    Small note on the change to the Contract, I've moved the emitting Observable to the view side. I believe this still respects the MVP model, based on this model:

    image

    Notes:

    • Changes to contract to reflect View's emitter/consumer nature when using Observables.
    • Example of using RxRelay to hide implementation details / lifecycle issues from presenter.
    • Example of using RxBindings on View side.
    • Added RetroLambda support.
    opened by kanawish 8
  • [main] User input for add/edit screen is lost across process death

    [main] User input for add/edit screen is lost across process death

    Similarly to older issues that have since been either closed or fixed such as https://github.com/android/architecture-samples/issues/370 and https://github.com/android/architecture-samples/issues/123 and https://github.com/android/architecture-samples/issues/731 and https://github.com/android/architecture-samples/issues/663

    This bug seems to have been long-standing, but with MutableStateFlow(UiState) it still persists - as on this screen, SavedStateHandle is used only for transferring screen arguments to the ViewModel, but is not actually used to preserve user inputs across process death.

    https://github.com/android/architecture-samples/blob/7e9d96d808a0d25a689d14099ecf0eb3ea7d5b1f/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskViewModel.kt#L39-L40


    On the other hand, TasksViewModel correctly persists the current filter state using savedStateHandle.getStateFlow.

    https://github.com/android/architecture-samples/blob/7e9d96d808a0d25a689d14099ecf0eb3ea7d5b1f/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt#L64-L65

    Filtering state on the tasks screen was originally fixed by setting it on the SavedStateHandle in this commit: https://github.com/android/architecture-samples/commit/cfb5ac6ea6a5c888b171d88d7ea4287a33af5cb9#diff-631edb6efa01767b52856a0e498dc3987e8a2f0e8ba02837377dfbc5684af0cfR111


    Therefore, AddEdit screen should also correctly save/restore user inputs across process death.

    opened by Zhuinden 0
  • [ADR Jam Week] Update sample app dependencies and optimize build

    [ADR Jam Week] Update sample app dependencies and optimize build

    • Updated dependencies that don't require updating the compileSdkVersion
    • Moved repository info to settings.gradle file (changed in AGP 7.1)
    • Turn off Jetifier check to optimize build
    • Enable configuration cache to optimize build
    opened by amylgu 0
  • CollapsingToolBar not working on tab switch

    CollapsingToolBar not working on tab switch

    When my activity is opened the first time I can collapse by dragging on the image but after switching to other tabs I can't collapse the layout by pulling on the image view. Once the view pager is scrolled, I can Collapse the toolbar using the top image view.Please look at the GIF on the link below. I think this is because of the view pager nested scrolling. I don't know the cause. but Why can't I drag the top Image view once the tab is switched?https://stackoverflow.com/questions/74611210/collapsingtoolbar-not-working-on-tab-switch

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:nestedScrollingEnabled="false"
        tools:context=".MainActivity">
    
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nestedScrollingEnabled="false"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbarLayout"
        android:layout_width="match_parent"
        android:nestedScrollingEnabled="false"
        android:layout_height="256dp"
        app:titleEnabled="false"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/tool_bg"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/black"
            android:alpha="0.3"/>
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolBar"
        android:layout_width="match_parent"
        android:layout_height="48dp"
         app:layout_collapseMode="pin"
        android:background="@drawable/fade"
        app:title="hello"
    
    
    
        android:layout_marginTop="4dp"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        app:menu="@menu/three_line"
        android:layout_marginBottom="48dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        />
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/transparent"
            app:tabSelectedTextColor="@color/white"/>
    </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>
    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    
    opened by AsitDixit 0
  • [Question] Which layer for VPN client business logic

    [Question] Which layer for VPN client business logic

    Hello, suppose we are building a vpn client, in which layer should the business logic and service class be placed? In the ui layer corresponding to its feature, or the domain layer

    opened by ErfanSn 0
Owner
Android
Android
Multiple samples demonstrating Search API usage in Android.

Search Samples Repository This repository contains a set of individual Android Studio projects to help you get started writing apps that take advantag

Android 43 Dec 16, 2022
This project was created as a demo project for implementing latest frameworks, Android APIs, tools, and techniques.

IWeather Android Application This project was created as a demo project for implementing latest frameworks, Android APIs, tools, and techniques. It fo

Ali Mansour 9 Dec 30, 2022
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 29 Jan 1, 2023
Event Trackr Android app. Allows users to track birthdays and anniversaries of friends and family.

Trackr Event Trackr Android app. Allows users to track birthdays and anniversaries of friends and family. You need to open this project in Android Stu

null 4 Dec 17, 2022
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Dec 30, 2022
Saga of Star wars - An Android sample repo showcasing Clean Arch with MVVM and Epoxy models

Star Wars Universe This is a showcase android application written in Kotlin and follows Clean Code architecture to showcase Characters from the StarWa

Adit Lal 5 Dec 13, 2022
eCommerce app developed with Android Jetpack and Kotlin

garden-shed eCommerce app developed with Android Jetpack and Kotlin This is my first mobile application. Garden Shed is a simple application for buyin

null 2 Nov 1, 2022
An Android project template with MVVM, Hilt, Navigation and Compose

compose-android-template An Android project template with MVVM, Hilt, Navigation and Compose ?? Status UNDER ACTIVE DEVELOPMENT ?? Terminologies Termi

Sifar 20 Oct 20, 2022
A simple android sound recorder which let's users record audio and listen to it

Android-Sound-Recorder A simple android sound recorder which let's users record audio and listen to it. Getting started To get started just clone or f

Nisa Jamalia Nurhayati 0 Nov 4, 2021
This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and Show The existing data. operations using SqLite.

SqLite Database Keywords : SqLite, Android, Database This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and

Rudra_deep 1 Nov 7, 2021
Starter code for Android Kotlin Fundamentals Codelab 4.1 Lifecycles and logging.

DessertClicker - Starter Code Starter code for Android Kotlin Fundamentals Codelab 4.1 Lifecycles and logging. Introduction DessertClicker is a game a

null 0 Dec 2, 2021
Android Viper template with Kotlin, Dagger 2, Retrofit & RxJava

Android VIPER Architecture Example This repository contains a detailed sample client-server app that implements VIPER(View-Interactor-Presenter-Entity

OmiSoft 33 Nov 4, 2022
Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Next 117 Dec 8, 2022
This is an example implementation of android accessibility services with 5 Sample Actions

Android Accessibility Services Example This is an example implementation of android accessibility services with 5 Sample Actions such as: Simulate Pow

Muhammad Fahriansyah 7 Jul 1, 2022
Android Modern Architecture Sample

AndroidModernArchitectureSample TODO: write readme Download (playstore release - under review) https://play.google.com/store/apps/details?id=io.github

Ji Sungbin 22 Sep 10, 2022
Example Android library project that works with jitpack.io

android-example Example Android library project that works with jitpack.io. See this Tutorial on how to publish an Android Library with JitPack. For m

Denys Denysenko 0 Dec 20, 2021
This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity.

Behind the Scenes - DevByte Viewer App This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity. DevByte DevByte Vi

Jaime 1 Oct 20, 2021
LoadApp This is my submission for the "Building an Advanced Android App"

LoadApp This is my submission for the "Building an Advanced Android App" project of the Udacity Android Kotlin Developer nanodegree. (C) Jaldhar H. Vy

Jaldhar H. Vyas 1 Oct 7, 2021
A Project suggested by the Android Basics Course

Dogglers - Starter Code Starter code for the second independent project for Android Basics in Kotlin. Introduction This is the starter code for the Do

Sorin Noroc 2 Aug 31, 2022