Sign in

Android dev @ hotstar

RxJava 2 introduced the concept of backpressure. Backpressure is nothing but a way for the subscriber to limit the number of items emitted by the emitter. Here we will take a look at how we can handle backpressure in RXJava2

What is the concept of Backpressure?

The concept of backpressure is that if the subscriber cannot accept any more of new events then the emitter should not send more events. Imagine this case where the subscriber is writing every item that it receives to a database. Now if the items are emitted at a very high frequency the subscriber will not be able to keep up…


The Hotstar social feed has an extensive set of features, which continues to grow as we continue to deepen engagement vectors in the product. Presently there are about 20 cards, each having a unique design & structure, varying functionality and in some cases, different teams developing and collaborating. This would have soon gotten out of hand and become unmanageable, however, we solved this by adopting a novel modular approach using RecyclerView for our Android app.

Our ultimate goal was to create a heterogeneous list with the ability to support several views and multiple teams to work in parallel on the…


“stocked yarns” by Alex Block on Unsplash

Realm is one of the finest alternatives to SQLite DB we have in Android. It is really easy to set up and fun to work with. Since realm lazy loads the data it is really fast to read.

Realm has its own pain points the biggest one being the multithreading. The realm managed objects (the objects that read from realm) cannot be passed across threads unless you convert them to POJO. The writes to the realm are painfully slow in certain cases(when you have listeners to the item you are changing).

Here are some of the things to remember when…


Anyone who has worked with the android custom views will be familiar with the onDraw method. This is where we draw the view to the android canvas to be shown on the screen.

We had to create a view which would rotate corresponding to a given viewRotation value. So my on draw method looked like this.

override fun draw(canvas: Canvas?) {

canvas?.rotate(viewRotation, (canvas.width/2).toFloat(), (canvas.height/2).toFloat())

super.draw(canvas)
}

Here the canvas is rotated with its centre as the pivot point. Everything works fine. The view is rotated and drawn to the screen according to the specified viewRotation value.

The view looks fine with the rotation.

Everything looked fine till…


A RecyclerView is more advanced version of ListView which reuses the same view to prevent additional creation of views to provide a smooth scrolling experience. The RecyclerView achieves this by keeping a View pool that holds the views that are no longer visible and can be recycled.

Sometimes we need to nest RecyclerViews to create some layouts. Consider the case where you have a horizontal RecyclerView inside a Vertical RecyclerView.

In the Image you can see vertical scroling list of horizontal scroling lists.This is achieved by placing a recyclerView inside another recyclerView.

When the user swipes the side-wise the inner…


SubscribeOn and ObserveOn, two concepts that eludes most Rx beginners . I too belonged to this before my experiments using them. Below is a snippet of code that has been used by me to gain deeper understanding about this.

I am emitting an empty string and the map is used to print the thread in which the method was called. The output of the logs can be seen as comment next to the code.

ch

ObserveOn works only downstream. All the methods following the observeOn have been moved to the IO thread. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store