Improving App Performance with Threading
Learn how to use threads in Android for improving the app's performance.
Introduction
Any application code is executed on either the main or worker threads. By default, all the application code is executed on the main
thread. If this thread contains long-running tasks, it might block the thread, resulting in an unresponsive app experience.
In this lesson, we’ll learn how to use different threads effectively to improve the app's performance.
Using thread priority
To recap, we can create a new thread using the following code snippet:
val thread: Thread = object : Thread() {override fun run() {// your code here}}thread.start()
By default, all threads have the same priority as the caller thread. If the thread were created on the main
thread, it would compete with the main
thread for resources. Therefore, an application that creates a lot of threads will result in degraded UI performance. The diagram below illustrates how the processor would handle tasks with the same ...