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) […]
Android Development
My Fave Android Studio Keyboard Shortcuts
I have been working on small Android apps, and I just want to share some of my favorite keyboard shortcuts. Some of them were manually added by me. Keyboard shortcuts are one of my must-haves for productivity as a programmer, as they let me navigate through code faster, allowing me to focus on creating new […]
val vs. const //Kotlin Android Dev Diary
Let’s start off by introducing val. To define a variable in Kotlin, you may use var or val: var val has a mutable value (changeable) has an immutable value (read-only) So we use val for immutable values, so what is the const keyword and what’s its difference from val? const val has an immutable value […]
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:
1 |
WordDao.java:21: error: Not sure how to handle query method's return type (java.lang.Object). DELETE query methods must either return void or int (the number of deleted rows). |
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
Error: Type mismatch. Required: ActivityMainBinding. Found: ViewDataBinding! //Android Kotlin Dev Diary
The problem is that this line of code is producing an error: And the error says: Type mismatch.Required:ActivityMainBindingFound:ViewDataBinding! The solution is to add a <layout> tag in the layout file that you are inflating!
Error inflating class androidx.fragment.app.FragmentContainerView // Android Kotlin Dev Diary
The cause of error in Logcat: The fix was to add a startDestination to <navigation> tag in the nav_graph.xml.
Expand ScrollView vertically if height is smaller than screen // Android Dev Diary
I have the following XML layout code in an Android app that I’ve been tinkering with: I wrapped my GridLayout in a ScrollView because on the landscape orientation of the Android app’s screen, my grid contents are cut from the view because they’re too tall, and there’s no way to see them without a scrollbar, […]
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 […]
Prevent Huawei from Killing Your App //Android Dev Diary
I have been playing around with Android app development, particularly on how to retain UI values after configuration changes and minimizing the app to launch a different one. To retain values after configuration changes, I use ViewModels. And to retain values after minimizing the app, the following is supposed to do the trick: But in […]
DataBinderMapperImpl Error: cannot find symbol (DataBinding) //Android Kotlin Dev Diary
Today I encountered the following error as I was building an Android app: Turns out, there’s an error in the related XML file, activity_main.xml! 😂 For other possible solutions, this StackOverflower answer may help: android: data binding error: cannot find symbol class