Is "ANR" an exception or an error or what?

lee lias picture lee lias · Jun 30, 2011 · Viewed 22.3k times · Source

Is the ANR an exception, an error or what? Can we actually catch it in a try{} catch(){} structure?

Answer

rogerstone picture rogerstone · Jun 30, 2011

ANR (Application Not Responding) is not exactly an error. It is shown when your application is very sluggish and takes a lot of time to respond, thus making the user wait. The user won't appreciate if your application makes them wait for a long time. So, the Android framework gives the user an option of closing your application. http://developer.android.com/guide/practices/design/responsiveness.html

This occurs when you are doing long running operations on the main thread. The system can't process user interactions during this period since the main thread is blocked. The solution is to do the heavy operations in a worker thread and keep the main thread free.