4 January, 2022

Android Development Notes

Android Custom Views

Custom View Components https://developer.android.com/guide/topics/ui/custom-components

DI with Hilt

After creating a project, setup Hilt https://developer.android.com/training/dependency-injection/hilt-android

In project's build.gradle:

buildscript {
    ext.hilt_version = "2.28-alpha"

    dependencies {

        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

In app's build.gradle:

plugins {
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'


dependencies {
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"



Persistence with Room

@MapInfo(valueColumn = "songCount")
       SELECT *, COUNT(mSongId) as songCount
       FROM Artist JOIN Song ON Artist.artistName = Song.artist
       GROUP BY artistName
fun getArtistAndSongCounts(): Map<Artist, Integer>

Theme and Styles

https://developer.android.com/guide/topics/ui/look-and-feel/themes https://medium.com/androiddevelopers/android-styling-themes-vs-styles-ebe05f917578

Configure build variants



Use suspend functions for long running work they can be called within a Coroutine.

suspend fun longRunning() = withContext(Dispatchers.IO) {


Block the current thread and start a new Coroutine. Use this in tests:

fun longRunning() = runBlocking {
  withContext(Dispatchers.Default) {



How to inject dependencies into a Room migration. https://blog.termian.dev/posts/room-on-upgrade/