Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 929
lee lias Avatar asked Jun 30 '11 19:06

lee lias


People also ask

What will cause ANR error?

Application Not Responding (ANR) errors are triggered when the UI thread of the application is not responding for more than 5 seconds. You can read more about ANRs and diagnosing ANRs in the Android documentation. Additionally, Crashlytics can help pinpoint specific problematic threads.

What is ANR how it can be prevented?

An ANR happens when some long operation takes place in the “main” thread. This is the event loop thread, and if it's busy, Android cannot process any longer GUI events within the application, and thus presents an ANR dialog.

What is an ANR notification in Android?

ANR or Application Not Responding is an android error that happens when the UI thread becomes unresponsive to the user. When the application becomes unresponsive, the user is presented with an ANR dialog that gives them the option to force quit the application.

How do you analyze ANR?

A good way to try to detect the problem is by fetching the file /data/anr/traces. txt which is generated after a ANR happens on a device (beware that it is overridden after another ANR happens). That offers you a overview of what each thread was doing at the time of the ANR.


1 Answers

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.

like image 132
rogerstone Avatar answered Sep 24 '22 15:09

rogerstone