Threads — Simplified

An application can have multiple threads, but the most important thread is the UI Thread / the main thread which is created when an application launched.

To simplify, the main thread will be the one who’s responsible for rendering what you see, the user interface, and the possible interaction between the user and the application (onClick, onKeyDown, etc).

But the main thread has its own limit just like your patience.

For example, you have a login screen and the user enters their credentials and clicks submit. Now you need to have an API request and you tried to put it on the main thread. Possible scenarios — the app will be frozen, laggy, or crashy (the app is not responding error message thingy).

Ugh. So what to do?

Create a separate thread for this process or any process that will/can take so long to end.

Creating a Thread in Kotlin:

So ezzzzzzz.

But you wanna complicate things. Like I wanna do this before this method I wanna do that after and such.

In Java, we have this so-called AsyncTask class. Howww?

Or using RxJava library + Kotlin:

Omg heard about Kotlin’s Coroutines? Let’s talk about it separately. ✌️

I’m still learning, please leave a comment if there’s something I need to improve/learn/elaborate. Thank you!

Android Developer | Newbie