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:

Replace the FragmentorActivityNameBinding above with the appropriate binding class name. Tip: The binding class name is based on the […]

Read More

Fix coroutine error: Cannot access database on the main thread // Android Dev Diary

As I was running a test for a ViewModel function, I encountered the following error: […] Main Thread @coroutine java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. I think it may be caused by the viewModelScope from viewModelScope.launch {} being used by […]

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

Sample Instrumented Test for Retained Text After Screen Rotation // Android Kotlin Dev Diary

First I added the following UI Automator to my app: So now my build.gradle (Module) file has the following dependecies: Then under the package app/src/androidTest/java/net/catzie/samplecalculatorapp I added the following instrumented test class: What it does is press the buttons 1, period, and 5 on the calculator’s UI to show “1.5” which should show up the […]

Read More