Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

We are not perfect, and even best of us make mistakes when implementing a new feature. Things sometimes go wrong and application breaks, resulting in a quite bad experience for the user.

There are 3 types of errors I would like to talk about. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

Basic idea of EventBus

In attempt to separate origin and handling of event, EventBus pattern have emerged in Android development community a few years ago. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

We already have one example of UI in the project: MainActivity that has a NavigationView on it, let’s add some more.

Main part of the display will be made by a Fragment, that will have MapView on it. That fragment will be displayed by MainActivity — it’s presenter will receive a showInitialScreen event from NavigationDrawerViewExtension. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

To better showcase approaches to architecture, let’s write some more code and make our sample an actual app.

Flickr on a map

As an example, let’s make an app that shows Google Maps, fetches information from Flickr and shows pins for pictures. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

Activities and Fragments are the most critical parts of Android application. Both represent an application screen that user will see. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

Before we start writing our first screen of the app, there are a few things we can setup beforehand. We can setup Dagger, agree on structure and prepare for testing.

Dagger 2

First let’s setup ApplicationContext and initialize dependency injection with Dagger 2. …


Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

Gradle is a build system that was introduced to Android a couple years ago. If you are still not using it — you should. The only downside I see is that Groovy is used to write scripts, but, luckily, there is already an initiative to bring Kotlin to Gradle. …


This series of articles will focus on practical approaches on how to write testable, re-usable and maintainable code when developing applications for Android.

Clean Android Code articles series:

  1. Clean Android Code: Main
  2. Clean Android Code: Building with Gradle
  3. Clean Android Code: Preparation
  4. Clean Android Code: Activities & Fragments
  5. Clean Android Code: Network & Data
  6. Clean Android Code: Navigation & UI
  7. Clean Android Code: Event Bus
  8. Clean Android Code: Error Handling
  9. Clean Android Code: ViewPager with View Pages
  10. Clean Android Code: Clean Adapter
  11. Clean Android Code: …

In the first article I will be talking about why do we need to do it, will provide a list of libraries that I strongly recommend to use in your apps and will present a basic architecture of how things could be done, with not much specifics. …

About

Anton Averin

Fullstack mobile developer @ Spring-media, Berlin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store