Keeping Your App Responsive
Android applications update its view based on a single thread model often known as UI thread. Due to this model applications can often lead to poor performance if the UI thread is not properly handled. This thread is responsible for handling all the UI related events or drawing events, for example if user pressed a button on the screen the UI thread dispatches the touch event to the respective widget which sets the button state to pressed state.
Since these operations are handled on UI thread, performing long operations like I/O or network etc. would result in sluggish user interface and poor user experience. Events will not be dispatched during long running operations on UI thread; thus blocking the whole user interface.
Applications that continuously block the UI thread for some time will show an ANR dialog (Application Not Responding)

In order to provide good user experience, all time consuming operations should execute asynchronously. These includes file access, network operations, database access and complex calculations etc.
There are several ways to execute lengthy operations asynchronously which requires thread management. In order to avoid painful thread management, Android framework allows to execute asynchronous tasks using AsyncTask. AsyncTask takes care of the thread management and allows to perform background operations on worker thread and publish results on the UI thread.
A detailed overview on AsyncTask can be followed on the official documentation. However, there is classical problem associated with the AsyncTasks which leads to IllegalStateException for example when a long running operation tries to update the UI and the interface is not accessible because the user has navigated away from the respective UI. While there can be workarounds to fix this problem using AsyncTask (bind/unbind) the view during the user navigation. However, a more better approach is to use RxJava/RxAndroid for a cleaner approach. You can follow Dan Lew tutorial to learn more about RxJava/RxAndroid.
To summarize the above discussion, below are two rules when taken care, increases the application performance.
- Do not block the UI thread and make sure only Android UI toolkit accesses the UI thread.
- Always execute long running tasks on background/worker threads.