Room persistence library is one of the easiest one to set up. However, when using data classes for your Room entities, you might face some small problem, which on the first look doesn’t really make any sense. Let’s try to compile this class: @Entity(tableName = "users") data class User( @PrimaryKey @ColumnInfo(name = "id") val number: Int, @ColumnInfo(name = "user_name") val userName: String, @ColumnInfo(name = "user_status") val userStatus: String, @Ignore val englishNameMeaning: UserGrade ) The problem:
_Inspired by myself and perhaps some other people, who coded Java style in Kotlin. I have seen tones of articles which (mostly) highlight Kotlins null safety and nothing more. So that’s it? If it was only for that I swear I would be still using Java with some null checks. Therefore, this article suggest what to use best in Kotlin as well as droping some everyday Java habits. _
While the Android architecture made development simpler, we should always be aware of the Lifecycle and with that, the right way to provide ViewModels. Creating one ViewModel factory for each Fragment and ViewModel you have is really expensive, bad architecture, and too much unnecessary code. Not to mention the fact that you should care about scopes, dependencies, components modules when using Dagger for DI. You can have a simple “generic” ViewModel factory for all your app as a Singleton, with the help of Kotlin Reflection and Daggers Multibinding.
Androids’ WorkManager has been around for a while. However my own expectations about it were a little higher. I wished that the WorkManagercould fire events at exact timing. But since it was made to respect doze mode, I should respect that too. That means that if the phone is idle, the WorkManager wont run. **Lets explore my case: ** Once the user logs into my app, I need to schedule 5 alarms for him.
Testing, testing testing. I was getting inside the “Fear of getting behind” every time I heard that word. So I decided to react quickly. I knew nothing about testing and this is my experience getting my hands dirty with it. Please feel free to correct anywhere I’m wrong. This is a reason why I’m writing blogs. So what the hell is testing? Testing is just a piece of code where you invoke your written production code and check its’ behavior.