Antipattern: freezing the UI with an AsyncTask
The worst thing that can happen to your app's responsiveness is an "Application Not Responding" (ANR) dialog. In my previous post I described how to freeze the UI with a Broadcast Receiver. It is very important to understand which methods run in Main UI Thread. In this post we can find an example OF WHAT NOT TO DO WITH AN ASYNCTASK . We use an AsyncTask to execute background tasks in order to avoid the UI to become unresponsive, but not all methods run on the background thread. In our AsyncTask class we must override doInBackground() which is invoked on the background thread. There are three other optional methods each of which is invoked from the UI thread : onPreExecute – this is called before doInBackground() onProgressUpdate – this is called while doInBackground() is executing onPostExecute – this is called after doInBackground() If your app ties up the UI thread for more than 5 seconds, Android will throw up the Application Not Responding (AN