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

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

Android Kotlin: “overrides nothing” error appears on instantiateItem() function of PagerAdapter

I just began learning Kotlin for work and one of the first errors I encountered is “overrides nothing” pointing at the overrides of the function instantiateItem() for my PagerAdapter The function/method signature was like this: override fun instantiateItem(parent: ViewGroup?, position: Int): Any { To fix the error, I simply removed the question mark from the […]

Read More

Android: Facebook SDK “Invalid Key Hash” on Ubuntu

I kept getting a different Facebook key hash from the one being actually generated by my debug app when it runs. Turns out I’ve been entering the wrong keystore password. To get your key hash for Facebook SDK on Ubuntu, run the following command:

In case you don’t have the keytool program yet, you’ll […]

Read More

Android: SharedPreferences not accessible from SyncAdapter

When I was trying to access a SharedPreferences value from my Android app’s SyncAdapter, I kept on receiving an old value that was saved to the key. Quick solution to inaccessible SharedPreferences from SyncAdapter A quick solution (which may be a short-term one) I tried was to remove android:process=”:sync” from the following code:

But […]

Read More

Android app dev: Missing import org.apache.commons.lang3.text.WordUtils;

I use a few instances of WordUtils.capitalizeFully() on an Android app that I’ve been working on. And there are times when the import org.apache.commons.lang3.text.WordUtils; breaks, sometimes after merging with some of my git branches. To fix this, what I do is open app/build.gradle and add the following line under dependencies:

Hope this saves somebody […]

Read More