Remove room database on app uninstall // Android Dev Diary

The problem: Installing on an Android device that has an old version of an app I’m developing triggers an error: Room Database Migration: java.lang.IllegalStateException: Migration didn’t properly handle Problem persists despite uninstalling the Android app and deleting all app data. The solution: Very simple. I set allowBackup to false in my AndroidManifest.xml file like so: […]

Read More

Get Navigation Component destinations in back stack // Android Kotlin Dev Diary

It’s simple to get the list of destinations that’s currently in your back stack. The only thing you need is a reference to the Navigation Component’s NavController. The NavController object has a backQueue property that you can inspect. backQueue is an array, and each item’s destination property is what you’re probably looking for! To show […]

Read More

A working shared ViewModel between parent and child Fragments //Android Kotlin Dev Diary

I initially had a problem with the shared ViewModel because the child fragments were creating a new instance from the one held by the parent fragment. The ViewModel instantiations below work for me: CreateLogFragment.kt (parent)

CreateLogFoodFragment.kt (child)

CreateLogNotesFragment.kt (another child)

by activityViewModels turned things around!

Read More

Two NavHosts with their own NavControllers and NavGraphs (Navigation Component) //Android Kotlin Dev Diary

I am trying to make a single-activity app because I’d like to easily share data across screen using, ideally one, or as few as possible ViewModels. NavGraph 1 Host: Layout file of MainActivity Destination(s): CreateLogFragment NavGraph 2 Host: Layout file of CreateLogFragment Destination(s): CreateLogFoodFragment, CreateLogNotesFragment (CreateLogFragment has a BottomNavigationBar that switches between CreateLogFoodFragment and CreateLogNotesFragment) […]

Read More

Dao Error: Not sure how to handle query method’s return type //Android Kotlin Dev Diary

As I brush up on my Room database knowlege I came upon the following error while building my app:

The solution: Set Kotlin version to 1.6.10 then Room to 2.4.2 (Or use more recent compatible versions) in my top-level build.gradle file. Reference: Android Room Kotlin throws Delete Query error

Read More