I get a kick out of automating things! Especially those seemingly easy extra steps that we do numerous times a day, everyday. There’s this configuration file that I frequently have to adb push into my test Android devices. And the cycle of editing the file, saving it, and then going to the terminal to run […]
Android Development
Make a RecyclerView expand its height when new item is added //Android Dev Diary
It seems that simply using android:layout_height=”wrap_content” on your RecyclerView won’t make its height automatically expand when new items are added in it.
How to start using view binding //Android Kotlin Dev Diary
First, open your app/build.gradle file Inside the android{} block of app/build.gradle, add the following: buildFeatures { viewBinding = true } Sync project with gradle files. In your activity or fragment, define the following class-wide property:
1 |
private lateinit var binding: <strong>FragmentorActivityNameBinding</strong> |
Replace the FragmentorActivityNameBinding above with the appropriate binding class name. Tip: The binding class name is based on the […]
Disable animations programmatically during instrumented tests // Android Dev Diary
When running an instrumented Android test, or “androidTest”, and you encounter the following error: It means that you need to disable animations for it to successfully run the test. But, it can take a lot of clicks on the emulator/device screen to get to the developer settings to turn off animations! So, for a quicker […]
Exception: No signature of method android() is applicable for argument types, Build Gradle // Dev Diary
Today I wanted to make a data class a Parcelable so that I could pass it as an argument in Navigation component. Parcelables, though better in performance than Serializables, take more time to implement! To help us out, there’s a “kotlin-parcelize” plugin that can generate the boilerplate code for us. There were issues though. After […]
Two-way data binding with StateFlow & BindingAdapters //Dev Diary
I created BindingAdapters for an EditText like so: My XML layout element looks like this: And in my ViewModel, the inputAmount is set up this way:
Grant, revoke permissions via Android Studio Terminal (ADB Shell) // Android Dev Diary
To grant and revoke permissions via Terminal (ADB Shell), run your app on an emulator (I haven’t personally tried on a device but it should work there too). Open your Terminal, and then enter the following command: adb shell Once you’re in, you may use the following syntax for granting or revoking your Android device’s […]
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: […]
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 […]
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)
1 2 3 4 |
class CreateLogFragment : Fragment() { private val mainViewModel: MainViewModel by activityViewModels { MainViewModel.Factory } . . . |
CreateLogFoodFragment.kt (child)
1 2 3 4 5 |
class CreateLogFoodFragment : Fragment() { private val mainViewModel: MainViewModel by activityViewModels( null, factoryProducer = { MainViewModel.Factory }) . . . |
CreateLogNotesFragment.kt (another child)
1 2 3 4 5 |
class CreateLogFoodFragment : Fragment() { private val mainViewModel: MainViewModel by activityViewModels( null, factoryProducer = { MainViewModel.Factory }) . . . |
by activityViewModels turned things around!