_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.
This post is no longer necessary. You can have a full example in this Stack Overflow answer