Photo by Sigmund on Unsplash

A great way to reduce, reuse, and recycle your code

The Delegation pattern has proven to be a good alternative to implementation inheritance”. This pattern allows composition to make code just as reusable as inheritance. Kotlin has made delegation a first class language feature through the by keyword. Kotlin supports delegation in two ways: Interface implementation and property delegation. These delegates will help you reduce boilerplate code, reuse common features and patterns, and recycle existing information into even more usable ways.

When you want to add a small piece of functionality to class in object-oriented programming you would generally start by extending that class. However sometimes this isn’t possible:

  1. The…


Photo by Ben Wicks on Unsplash

While we’re waiting, here is a way to implement multiple receivers now!

During the Kotlin 1.4 Online Event in 2020, Roman Elizarov discussed a potential future feature, Multiple Receivers for extension functions/properties¹. With member extensions you can access the properties and methods of the container class allowing you to have multiple receivers to your extensions. However, if you are not the creator of the class it can appear nearly impossible to make use of multiple receivers. Unfortunately, Roman says in the talk they are a long way from implementing this feature. …


Photo by Jannis Brandt on Unsplash

The secret to losing weight successfully.

When most people notice or hear that I lost weight, they tell me they gained weight during the pandemic. The next question is, “How are you doing it?”. After they hear my method they always respond with varying levels of seriousness to sarcasm, “No magic pill?”. Nope! Just tried and true calorie deficit, exercise, and working with a mentor/coach.

In March 2020, just before everything shut down, I signed up for my company’s wellness program. This program assigned me a coach that I could meet with weekly to go over my progress, challenges I am facing, and help me make…


Photo by Patrick Lindenberg on Unsplash

A better way to store preferences

On Sept. 2, 2020, the Jetpack team released the DataStore library to alpha. This library is the replacement to SharedPreferences and it is awesome! DataStore comes in two flavors:

  1. Preferences — for storing key value pairs.
  2. Proto — for storing custom data types using protocol buffers.

Proto DataStore has some additional setup and requires you to define a protocol buffer schema, ensuring type safety. Preferences DataStore is much easier to setup but doesn’t provide any type safety. This article will explore Preferences DataStore¹.

First, let’s start by looking at how we create a PreferencesDataStore:

val dataStore: DataStore<Preferences> = context.createDataStore(…


Photo by Benjamin Voros on Unsplash

Convert any callback API into a self cleaning Flow.

Kotlin Flows are amazing. Not only do they provide a non-blocking asynchronous way to deal with sequences of values, but they provide a clean and powerful API for dealing with event driven programming. Flows are easy to clean up to prevent leaks. They provide many functions and operators to deal with a myriad of scenarios and requirements. With an experimental function they are super easy to create around callback APIs.

The Jetpack team added CoroutineScope support to the lifecycle in lifecycle-runtime-ktx version 2.2.0-alpha01. This allowed callers to launch coroutines in created…


Photo by K. Mitch Hodge on Unsplash

Help prevent remote meeting interruptions

Children interrupt BBC News interview

In April 2020, at the start of the global quarantine, Elio Struyf posted an article detailing how to use a Raspberry Pi Zero W and Pimoroni Unicorn pHAT to create a busy light or in meeting indicator for your home office. After some interruptions in work meetings, I decided to build one of these indicators. However during this process I ran into a couple of issues and discovered areas I wanted to improve.

First off Elio’s solution uses a server running on the Raspberry Pi to control the lights and a Homebridge plugin to poll…


Photo by Ken Suarez on Unsplash

Key attributes that will help propel your team to function at a higher and healthy level.

A few years ago my team was 3 developers covering 16 apps.We released 4–5 times a month and maintained 4+ star ratings in the Play Store during this busy time. These apps ranged from business style apps, to multimedia apps, to book reader apps. During this same time, we outpaced the much larger iOS team, which comprised eight developers compared to our team of three. …


Photo by Leonardo Gomes on Unsplash

You should really be using canary builds

I remember sitting in the audience at Google I/O 2013 and hearing the announcement that Android Developers had a new IDE built on top of IntelliJ, as well as a new build system based on Gradle. This was the biggest announcement of that entire conference. Up to that point, my team had been using IntelliJ and Maven with the Jayway Maven Android plugin. Our gamble of not following Google with Eclipse and Ant paid off.

Android Studio (Studio) and the Android Gradle Plugin have come a very long way in the past 7 years. Some great features include profilers, device…


Photo by Markus Spiske on Unsplash

The release of Hilt is one of the best things to happen to Android development.

I have been developing Android applications since 2012, and at that time the main dependency injection library was RoboGuice. Dagger 1 went 1.0 in May of 2013. Dagger 2’s initial release was in May of 2015. I have had the privilege to use all three libraries and see the change to dependency injection for Android over the years.

RoboGuice was an Android port of Google Guice. It supported more features than just dependency injection, such as layout injection. …


Photo by Mark Rabe on Unsplash

Update: With the release of Hilt, this article is no longer useful as a guide and the library has been deprecated. For more information read my article about Hilt.

Nimrod Dayan wrote a great article on Saving UI state with ViewModel SavedState and Dagger. He goes through and demonstrates how to use Dagger, ViewModels, and Saved State module for ViewModel together with AssistedInject. However, we are left with a large amount of boilerplate by the end.

Factory and Module Boilerplate for ViewModel Injection

He references a presentation by Jake Wharton Helping Dagger Help You at Droidcon London 2018. …

Jordan Hansen

I have been developing Android Applications professionally since 2012.

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