4

I get ANR on both occasions:

throw new NullPointerException("random null pointer");

and

while(true){}

Only in exception part VM actually shuts down (D/AndroidRuntime﹕ Shutting down VM).

Second question is: How to force app to crash instead of ANR and get stack trace in logcat?

Update Changed Title From what is difference between ANR and Crash.

Update It occurred only about 3-4 months ago. Since then, only way to find what's crashing is to put try catch boxes everywhere with no reason at all.

Alpha
  • 1,754
  • 3
  • 21
  • 39
  • Probably ANR occurs when you try to do heavy work in main thread, crash may cause in many reasons ex : if you dint give permission for a activity in manifest then you supposed to face the crash. you can find many interesting article related to this in google, do search – Madhu Jul 02 '15 at 09:18
  • ANR occurs on every RuntimeException. App do not insta crash like about one year ago, it just freezes and dose not return any stacktraces. – Alpha Jul 02 '15 at 09:21

5 Answers5

5

I am facing the same problem and when I am debugging I reach the code "throw RuntimeException" but I am also having an ANR instead.

The only clue that I have is that it started to happen when I configured Google Analytics in my app. Is this your case, @Alpha ?

I haven't gone beyond because I am kind of dealing with it like this, but some day I will debug specially for this issue with analytics.

EDIT: The issue is solved in Google Play Services 8.4. We can finally report uncaught exceptions! The app seems to be blocked for some seconds but finally exception is thrown and reported without ANR.

Javier Delgado
  • 2,343
  • 2
  • 17
  • 31
  • Yes, when i turn of GoogleAnalytics (Comment out lines), it works as it should. I guess there is nothing i can do, so probably i will accept your answer. – Alpha Jul 20 '15 at 10:32
  • 4
    I have found that the set up that causes the error is: tracker.enableExceptionReporting(true); If you don't turn it on (which is the default), it works correctly. You can find more information here. It seems to be a bug that they haven't resolved since version 6.1 of Google Play Services: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=82157 – Javier Delgado Jul 20 '15 at 14:15
  • i figured out this my self actually. But thanks for link to that bug. :) – Alpha Jul 20 '15 at 14:26
  • @Fighter42 I love you. Disabling GoogleAnalytics' crash reporting finally resolved my similar issue with ANR instead of good old crash. You should edit your answer and write this info in bold. – Den Drobiazko Jul 30 '15 at 15:42
  • I have edited my answer because the issue is solved in Google Play Services 8.4. – Javier Delgado Mar 16 '16 at 10:21
2

Crash : the application has stopped because it threw an unchecked exception, so the JVM stops.

ANR : your application stopped responding, meaning the UI thread is blocked by an expensive or long operation. For example, doing while(true){} on the UI thread.

I don't think you have a way to catch the system's built-in mechanism that triggers ANR dialogs so you could throw a RuntimeException and have your app crash. I'm not sure why you would want to do that either, it would be much better to try and follow guidelines here so you can avoid ANR and crashes altogether.

2Dee
  • 8,609
  • 7
  • 42
  • 53
  • I get ANR's instead of crashes. (NullPointerException = ANR ). When i write every thing in try catch block, i catch Exceptions and every thing is fine. – Alpha Jul 02 '15 at 09:37
  • You're telling me that the Android system is suggesting you, via an ANR dialog, to wait for an application that crashed due to an NPE ? You must be running a very custom ROM ... – 2Dee Jul 02 '15 at 09:39
  • Very LG g3, Sony xperia Z3, Sony xperia sp (original roms). Even galaxy tab4. – Alpha Jul 02 '15 at 09:41
  • in app store i don't get any crashes any more. Just ANR's. – Alpha Jul 02 '15 at 09:42
  • That's simply impossible, IMO. Note that an "Application Has Stopped" message is **not** an ANR, ANR is only the dialog telling you the app is not responding. One of my test devices here at work is a G3, I just tested it, I get a crash when throwing RE's. – 2Dee Jul 02 '15 at 09:44
  • Is it possible, that multidex or new android build tools causes this? – Alpha Jul 02 '15 at 09:44
  • I don't think so. Basically, if the app crashes, the JVM shuts down so it would be quite illogical for the system to still provide you with the option to wait for the app to recover, since there is no way it could recover from a crash. – 2Dee Jul 02 '15 at 11:10
  • I have the same issue as Alpha. Even if I throw a RuntimeException a ANR occurs. Disabling of the Google Analytics reporter as described in Fighter42s comment helped. So this is a bug of GA – maysi Aug 06 '15 at 09:10
0

App Crash/Force Close

http://www.quora.com/What-causes-Android-apps-to-force-close

If the app uses up too much memory or processing power, the app will be forced to close (crash). The best way to make sure that doesn't happen is to write very efficient code that doesn't use a lot of memory, and to constantly test your application on a variety of devices (primarily the older devices because they have less RAM and processing power).And exceptions too behind the reason.

ANR

http://developer.android.com/training/articles/perf-anr.html

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
  • This only explains the part of "while(true){}" But why runtime exception causes ANR and not crash? – Alpha Jul 02 '15 at 09:29
0

I had this problem when changing the default exception handler. In my case I had a NullPointerException when catching the exception, which caused a loop, which caused the ANR.

Like @Fighter42 mentioned in a comment, it can occur in any library which overrides the default exception behavior.

Hope this helps!

teh.fonsi
  • 3,040
  • 2
  • 27
  • 22
0

I am using now Google Play Services 8.4 and uncaught exception do not cause ANR anymore. I have been using it for a while and it may be OK in earlier versions too.

The result now is that when there is an uncaught exception, the UI does not respond for some seconds, but finally the exception is thrown and reported in Google Analytics.

Javier Delgado
  • 2,343
  • 2
  • 17
  • 31