RSSAmplifier

Blog

Android Essence

Recent content on Android Essence

androidessence.comRSS feed ↗61 posts

Latest posts

Leave Me Behind

“If you don’t learn how to use AI, you’re going to be left behind.” So leave me behind. I learned to build Android applications in 2014. I was in college taking a Java programming class, when a classmate shared a free online course to learn Android development. The goal was short: build a todo list app with local storage. When I completed the minimum requirements, I unplugged my phone from my…

Managing Multi Table Inserts With Room

A properly relational database may have a type that appears referenced multiple times. In my SpaceNerd playground app, that is the Country object. An Agency has a country, and an Agency is a dependency of a Launch, of a Space Station, and likely more types to come. How do I enforce that any time I insert an Agency, I also insert the Countries associated with it? That’s what this blog post…

Reflecting On A Decade Of Content Creation

Ten years ago today, I published my first blog post . There’s something special about looking back an entire decade at an achievement like that. A chance to reflect on what my life was like then, the motivations that got me into writing, and where I am today as a result. It has been an honor to learn in public over these last ten years, whether that be here on AndroidEssence, on Twitch , on…

Sharing Shared Element Keys

Shared Element Transitions are a fantastic way to add visual flair to your applications. They allow us to animate content between two separate screens. One complication is sharing keys for these components across different screens in a consistent manner. Let’s explore one simple option.

Wrapping Android XR For KMP

Recently I’ve been finding myself immersed in Compose Multiplatform , a way to build cross platform mobile applications with Jetpack Compose UI. Of course, when Android announced their extended reality framework Android XR this week, I initially worried I wouldn’t be able to try it out in my newest side projects. However, one of the biggest benefits of KMP is how seamless it is to…

Interface Naming Conventions

Many engineers will tell you that one of the most complicated responsibilities of our job is naming things. Variables, classes, functions, everything we write requires conscious thought. A special case among these are interfaces. This is because we not only have to name an interface, but we need to decide how to name the implementations as well.

The Imposter's Guide To Dependency Injection

Dependency Injection is one of the hottest topics in Android and software development in general. It’s also a topic that can provide a lot of anxiety and create imposter syndrome for developers. In this post, we’ll take incremental steps toward understanding DI, why we need it, and how to implement it inside our applications.

Five Essential Developer Experience Concepts For Android

In the most recent live stream for Tasks Of Affirmation, we looked at creating a good developer experience. It’s important to consider developers at the start of any new project, so we can ensure that over the lifetime of a project anyone who contributes can understand how to contribute, match any guidelines that a team has, and get up and running quickly. We also want to ensure that our…

Tasks Of Affirmation: A New Twitch Live Stream Series

In the late summer of 2020, I began live streaming on my Twitch channel . We started off by building an Android Study Guide application. The purpose of the application was to build something people would be interested in using, while also taking the opportunity to build an application out in the open. For a number of reasons, discussed in the latest video , I’ve decided to sunset that…

Unit Testing Custom Lint Checks

In our previous post we looked at writing a custom lint check to enforce usages of a custom view instead of an Android framework implementation. In this post, we’ll go over how to unit test such a scenario, and take the opportunity to look at some additional options of unit testing with lint as well.

Enforcing Custom View Usage With Android Lint

Sometimes an Android project will have to implement a custom view that is an extension of an existing Android view. We may do this for style purposes, or to implement additional logic, or any number of customization purposes. This solution brings a new problem for our codebase - how do we enforce that other developers use our custom view, instead of the Android framework view? We can solve this…

Storing Network Responses With Apollo Normalized Cache

In our previous post we looked at the HTTP cache from Apollo Android for storing network responses. In this post, we look at its counter part, the normalized cache .

Storing Network Responses With Apollo HTTP Cache

Caching is the practice of storing data that we requested previously so we can serve it faster in the future. This creates a better user experience by decreasing loading times. It also has long term benefits like reducing the number of network requests, to save on phone resources or potentially provide offline support. Today, we’re going to discuss how to use the HTTP cache for the Apollo…

Comparing Three Dependency Injection Solutions

During a recent live stream on my Twitch channel, we explored three different solutions to dependency injection on Android. A do it yourself approach, Koin, and Dagger Hilt. Let’s revisit them side by side, and look at the nuances between them, so we can determine which solution we want to use in our own applications.

Mastering Room Database Migrations

In the last post, we demonstrated the different types of database relationships in Room . Next, we’re going to explore another niched concept of Room database management: database migrations. A migration is a way to handle moving from one version of a database to another as users update your application from the play store.

Room Relationship Recap

In this post, we’re going to explore some advanced concepts of the Room Persistence Library . Room is a great tool for storing complex data for your Android applications inside a SQLite database. As you begin to store more data in your applications though, it can be difficult to determine how to organize all of it. We’re going to demistify database organization, and break down…

Getting Started With Test Driven Development

One of the many buzzwords thrown around the software devleopment community is Test Driven Development, or TDD. It is one of those phrases that sounds great when you say it - who wouldn’t want to have tests be their first priority when writing code? However, it’s not always clear what TDD means. Does it mean you write code with testability in mind? Does it mean writing tests first? How…

Contributing Code Samples To Kotlin Documentation

The Kotlin language used by Android developers all over the world is open source and available on GitHub . This means it’s open for contributions from anyone! It may, of course, feel very intimidating to contribute to a project of that size. Especially for those of us who are new to open source contributions. The JetBrains team makes this process a lot less scary than it sounds. There are…

MVWTF: Demystifying Architecture Patterns

As an Android developer, one of the questions I constantly see asked within the community is “what architecture pattern should I use?” This discussion usually leads to a handful of buzzwordy acronyms: MVC MVP MVVM MVI MVU?? (We don’t talk about this but apparently it’s the new kid on the block) This can be really intimidating to new Android devs, as well as seasoned…

Repository Pattern: Properly Organizing Your Data Layer

How to properly architect your application is a concern we as developers constantly face. There’s unfortunately no one size fits all answer to it, and sometimes we don’t even know where to begin. I’ve learned along my Android journey that the answer can also vary depending on what portion of your app you’re trying to organize. Of course, you might say, it depends . When it…

Unit Testing RxJava Or Coroutine Code With Constructor Injection

Putting aside the long lasting debate right now about whether you should use RxJava or coroutines for your asynchronous code on Android, both camps often hit the same problem. How do I write unit tests for this? Unit testing asynchronous code is tricky, because we may need to know how to properly test callback APIs, or perhaps we just want things to run instantly and not worry about thread…

Showing A Fragment For A Result

A number of developers preach a single activity architecture on Android, which is something I’ve been trying to move forward to as well. In the process, though, I ran into one tricky problem. I don’t have something like startActivityResult for fragments. If you’re unfamiliar, startActivityForResult is a method that allows you to launch an activity with a specific request code,…

Building An Application With MVVM

This is the second post in what will be an ongoing series to demonstrate a few different architecture patterns that are used for Android development. You can find the code for each of them, often appearing before the blog posts, by following this repo . Give it a star! In our previous post we discussed the MVP architecture for building an app. This time, we’re going to check out MVVM.

Building An Application With MVP

This is the first post in what will be an ongoing series to demonstrate a few different architecture patterns that are used for Android development. You can find the code for each of them, often appearing before the blog posts, by following this repo . Give it a star! The first architecture pattern we’re going to walk through is MVP.

Breaking The Buzzwords Barrier Part 3: ViewModel

So far we’ve covered four big buzzwords used in our application: Model-View-ViewModel Room RxJava Repository Pattern Now, we should circle back to the beginning. Following our diagram outlined in the previous parts , the next component we can begin to work on is our AccountViewModel: Naturally, this may bring up some confusion. We already discussed ViewModels in part 1 . Well, depending on…

Breaking The Buzzwords Barrier Part 2: Rx, Room, and Repository

In part 1 we discussed how we were going to architect the various components of our application. Now it’s time to build them. To understand what we should build first, we should revisit the diagram: I would start with three spots: The account The database The repository A good rule of thumb to remember this, is that these nodes don’t depend on anything else just yet (well, the…

Breaking The Buzzwords Barrier

MVVM? Retrofit? RxJava? Data binding? Architecture components? LiveData? Kotlin? Right now, these buzzwords are heard all over the Android community. Every podcast/blog/conference talk is referencing one of these. Which can be very intimidating to new developers. Which one should I learn first? Do I need all of them? What are these things even used for? The purpose of this series is to break all…

Breaking The Buzzwords Barrier Part 1: MVVM

When you’re starting out with Android development, and even as an expert, you will hear about a lot of different architecture patterns. Anything from: Model-View-Controller Model-View-Presenter Model-View-ViewModel Model-View-Intent It can be extremely hard to know which one to pick, what their differences are, and why they matter. I will tell you that even with my three years of Android…

Fingerprint Authentication Tutorial

When Android released version 6.0 Marshmallow (yes, a little outdated at this point), a whole slew of new developer APIs came with it. One that I’ve personally enjoyed as a consumer is fingerprint authentication . I skimmed over the official docs, and even through their Fingerprint Dialog Sample but had a difficult time following what was going on. Eventually, though, I was able to recreate…

Developing And Publishing Android Libraries

Third party libraries are a huge part of mobile app development. Popular tools like Retrofit, RxJava, Picasso, and many others prevent Android developers from reinventing the wheel everytime we need to do something over the network, asynchronously, or loading images. However, developing and publishing these libraries can be intimidating to many people. I think this occurs for a number of reasons -…

App Review: Digilux

DISCLAIMER: This application no longer exists in Google Play, but the post has been kept for posterity. Controlling the brightness of your phone can be a hassle. Currently we’re stuck with the two step process - swipe down on the notification drawer, and then deal with the slider trying to get it just right. However, with the release of Android Oreo and a new fingerprint gesture API , a new…

Leveraging The Robot Pattern For Espresso Tests

Espresso is a testing framework for Android that allows developers to write automated tests for their applications. The benefit of automated testing is that you can write a test plan, and simply hit run and have all of the important features in your app tested effortlessly, and arguably more consistent and thorough than manual testing. There is no doubt that it is a lot faster. However, one of the…

Understanding Nullability In Kotlin

Every Java programmer has faced the dreaded NullPointerException at some point in their life. Sometimes it’s your fault, sometimes it’s a pesky race condition. Regardless, it’s a head ache and generally leads to a ton of if (myVariable != null) { } conditions all over your code. However, the latest craze Kotlin can help with that too. Kotlin introduced null safety into its type…

Getting Started With Room Persistence Library

This year at Google I/O, the Android team announced Android Architecture Components a combination of new, helpful libraries for Android development. One that particularly interested me was the Room Persistence Library , which is an abstraction layer of SQLite designed to make database access and creation a lot easier. Right off the bat it reminded me of Realm , which I learned about at Droidcon…

How To Build A Todo List In Kotlin Part 1: Creating A New Project

This blog post is going to discuss creating a project from scratch in Kotlin. We will build a sample Todo List application that will not be very complicated, but covers enough to show the benefits of Kotlin. Part 1 will discuss creating a new project and configuring Kotlin. If you’re familiar with that, copy the MainActivity.kt code and skip to part 2 to begin building the app. This tutorial…

How To Build A Todo List In Kotlin Part 2: Implementing A RecyclerView

Following up on part 2 which demonstrates how to create your Android app and configure Kotlin, we’ll begin building the heart and soul of a Todo List application - the list!

How To Build A Todo List In Kotlin Part 3: Adding Items

Following parts 1 and 2 you should have a working Android app in Kotlin that displays a list of Tasks to be completed and lets you mark them as complete. This segment is going to show you how to implement support for adding new items.

How To Build A Todo List In Kotlin Part 4: Storing Items

If you’ve been following along with parts 1-3, you now have an (almost) working todo list application. The only thing we are missing is persisting the data. Running your Android app now and rotating your screen will show you that the items you add won’t persist, and disappear anytime an activity is killed and recreated. This post will show you how to write the list to a text file and…

Maintain Library Versions ACross Modules

It is tough enough maintaing your app by updating the support library version numbers every time a new version is out, let alone factoring in any other third party libraries you may use. This is especially painful if you have multiple modules, as you have to update the version in each build.gradle file. Thankfully, we can make use of the project level gradle file to make this more maintainable.

Creating Android App Shortcuts

Android app shortcuts are a special feature added in Android 7.1 (API 25). Shortcuts are special actions that appear when you long press on a launcher icon, that will trigger a specified intent. With this post you will learn how to create both static and dynamic app shortcuts. The only pre-requisite is that your app is targeting API 25 or greater. Static Shortcuts Static app shortcuts are…

PinchZoomTextView Library Released

I was recently asked if there was a way to increase/decrease the font size of a TextView by pinching on it, just as you can with many iamges. Well, it turns out that’s quite possible! All you have to do is override the onTouchEvent() method of your view, which is exactly what I do in my latest library, which allows you to pinch your screen to zoom in and out of a TextView. Check out the…

Getting Started With Retrofit In Android

As a new or intermediate Android developer, getting started with Retrofit , a popular HTTP client, can seem pretty daunting. However, using this library is not as scary as it sounds. Here are four easy steps to creating your first Retrofit application!

RecyclerViewUtils Library Released

Recently, I became tired of writing the same old tedious code for every single RecyclerView and Adpater class I used, that all did the same thing, so I extrapolated all of it into a personal library. The RecyclerViewUtils library helps make everyone’s life a little easier with a CoreViewHolder and CoreAdapter class, described below.

MaterialSearchView Library

Android has a built in SearchView component but it doesn’t feel much like Material Design. This has even been asked on StackOverflow because developers are having trouble recreating the same MaterialSearchView that appears in many of Google’s applications. However, thanks to one of my good friends Maurício, you can now implement this great component in your own projects!

RichTextView Library Released

As a form of ultimate procrastination this weekend, I decided to spend the last two days developing a RichTextView library. This weekend I built the RichTextView (the naming convention comes from the RichTextBox C# class) which allows the user to format different parts ofa. TextView in different ways. For example, if I wanted to display a string but only bold a portion of it, I could achieve that…

Designing User Interfaces For Android Wear Part 2: Cards

User interface for Android Wear have all the same components as a phone’s UI, they just appear a little differently. In this post we’re going to talk about Cards. You’ve most likely seen these in the Google now app, among other Material Design apps. Cards are great because they are a component that is able to provide a consistent look across multiple platforms. We will consider…

Designing User Interfaces For Android Wear Part 1: Lists

Rising in popularity after the latest Google I/O, Android Wear is a game changer for mobile development. Wearable technology has brought benefits from a quicker access to information to a more accurate monitoring of our physical health. Developing for this platform allows you to tap into those features that are not as readily available on mobile handhelds as well as offer a more immersive…

Material Design Specs Library

Along with the RecyclerViewCursorAdapter library that was released earlier this week, I have now released my second open source Android library. In collaboration with my good friend Maurício , we have built a library for including the Material Design Specs in your Android application. Currently, the library has the full color palette along with some helper methods, and some elevation resources to…

RecyclerViewCursorAdapter Library

Today I released my first library which is for a RecyclerviewCursorAdapter. Using a ListView to display database data becomes a lot easier when you use a CursorAdapter combined with a CursorLoader to display data from your ContentProvider. The main benefit of CursorLoader is explained in the docs:

How To Make An Android UI Part 2: Java Code

After reading part one which discusses what Views and ViewGroups are, as well as how to create them in XML, the next step is to incorporate them into your Android application. How you use the UI you wrote depends on what it’s used for. Let’s break down some of the key things: