In MVVM, ViewModel exposes streams of events to which the Views can bind. Generally, we use LiveData inside ViewModel and the view can observe for live data changes.
When it comes to unit testing for ViewModel, we create an observer, passes that observer to Live data, and verify its changed event.
You can explore this approach in the below article.
Let take an example, we make a simple API call, we show loading, then hide loading based on API event, then show data/error. So we have 3 states to represent. Thanks to Kotlin, we have sealed class
In my previous articles on unit testing, I have talked about ViewModel, Usecase, Repository testing using JUnit & Mockito. Today I am going to explore about Spek framework for unit testing.
Spek is a Kotlin-based Specification Testing framework. Spek is written in Kotlin and specifications or tests we write will be in Kotlin. However, our SUT (System Under Test) can be Java or Kotlin.
Currently, Spek is implemented as a JUnit Platform TestEngine. This means that we can easily plug it into any project that already uses JUnit 5.
This allows us to easily define specifications in a clear, understandable…
Recently I was working on Google Maps markers and I had to handle multiple marker states like Loading, Pickup, Destination, and other information on the markers. Markers indicate single locations on the map. We can customize markers by inflating our own layout and based on our use-cases.
Here are some demo examples where custom makers are useful. The most common examples are markers on cab services. We have seen ETA on the marker, Location, direction, etc on the marker.
If you want to skip this then please use the below link for demo.
lets take a simple example where we…
This is part 3 of the android interview experience. You can also read my previous articles on android interviews.
Android Interview Questions Part 1
Android Interview Questions Part 2
Recommended: Please solve it first, before moving on to the solution.
In my personal opinion, a good way for preparing any kind of interview is that after the interview gets over, note down all the questions that were asked in the interview and try to find the solution for the questions that you were not able to answer at the interview time. So I am going to share a few of the questions.
You can also read a few questions from my previous article.
Sometimes while developing an application, we have encountered a situation like based on some logic, we have to render some new view in the layout that is rarely used. A general approach for this is to make View visibility GONE/VISIBLE.
So always inflating this rarely used view in a layout, is not a good idea and also it impacts the rendering of the layout.
So what to do in this case?
Recently I was working on Google Maps with custom marker layout and I was inflating custom marker layout and creating bitmap from that layout as MarkerOptions accepts bitmap. So layout inflation + bitmap generation was happening in main-thread (fragment). This could create unresponsiveness and jank.
so, I search for this scenario and found AsyncLayoutInflater.
What is AsyncLayoutInflater?
Helper class for inflating layouts asynchronously.
When to use AsyncLayoutInflater?
This is intended for parts of the UI that are created lazily or in response to user interactions. …
Many of us already used it or some might be using it. Let’s explore more about data class in Kotlin.
What is a data class?
Data class is used to hold data/state and contains standard functionality.
In Kotlin, data keyword is used to declare a class as a data class.
How to create data classes in Kotlin?
data class Person(val name:String)
data class Person() this is invalid declaration of data class
In this article, we are going to learn how to use these 5 scope functions. Many of us have already used these functions. So what we need to learn about them
How we should use them?
and when we should use them?
The way they perform, sometimes become the cause of confusion.
let's learn more about them. We will take the example of webview.
so we will set few properties of the webview.
It is convenient when you have to call multiple different methods on the same object. Instead of repeating the variable containing this object on each line…