I used to check the docs and just read a lot about flows but didn’t implement anything until yesterday. However, the API tasted really cool (even though some operations are still in Experimental state). Prerequisites: If you don’t know RxJava it’s fine. But a RxJava recognizer would read this faster. Cold vs Hot streams Well, I really struggled with this concept because it is a little bit tricky. The main difference between cold and hot happened to be pretty simple: Hot streams produce when you don’t care while in cold streams, if you don’t collect() (or RxJava-s equivalent subscribe()) the stream won’t be activated at all.
This post is inspired by @EpicPandaForce answer in StackOverflow. I faced the same problem which I didn’t know how to solve: How to perform search when you are using a Paging Library (or how the hell to refresh after I reperform Rooms query)? Let’s suppose we have this scenario: I have a list of data, which are shown in the Fragment by LiveData observation, which are retrieved by the ViewModel through LiveDataPagedListBuilder().
There are times, when we just need the data when the app starts, and all the functionality is just a matter of work. Or we just need the app to be independent from the network and we have the data. A simple dog-race database or cat-race database doesn’t actually need online interaction at all (if there are not too many data of course). So, Room comes with a nice solution about this.
The ViewPager2 is a pretty nice rework of the ViewPager API. Some new features you may find with the ViewPager2 are: 1- Vertical scrolling. You can simply enable it by adding: android:orientation=“vertical” in the tag in your xml file. 2- Right to left support: you can set the android:layoutDirection=“rtl” to enable this. 3- Support for DiffUtil, because it is based on RecyclerView. 4 - Fragments improved support, which we will talk about below.
Kotlin is a very a pretty nice adoptive language and user friendly. It really replaced Java from my everyday programming. However, it was not enough. We all know that groovy runs on JVM. So, why do I even need a new language just for my builds? Can’t it be Java? So Java is the basic language for the JVM, Kotlin runs on JVM, Groovy runs on JVM and my build system has a separated language from my business logic system.
Conditional navigation is a little tricky when it comes to Navigation Architecture. There are plenty of nice articles and solutions about it, but I’m sharing the way I solve this important problem. So let’s consider this use case: If you don’t put HomeFragment as a start destination, you will have some serious trouble with the fragment back stack and you would need to write the onBackPressDispatcher in every fragment.