What is the difference between ANR and crash in Android?

前端 未结 13 2170
北海茫月
北海茫月 2020-12-07 22:56

I have searched on the internet regarding what an ANR is. And I studied those references as well. But I don\'t get details regarding a crash in Android.

Can someone

13条回答
  •  囚心锁ツ
    2020-12-07 23:18

    ANR stands for Application Not Responding.

    An ANR will occur if you are running a process on the UI thread which takes a long time, usually around 5 seconds. During this time the GUI (Graphical User Interface) will lock up which will result in anything the user presses will not be actioned. After the 5 seconds approx has occurred, if the thread still hasn't recovered then an ANR dialogue box is shown informing the user that the application is not responding and will give the user the choice to either wait, in the hope that the app will eventually recover, or to force close the app.

    A crash is when an exception within the app has been thrown which has not been handled. For example, if you try to set the text of an EditText component, but the EditText is null and there is no try catch statement to catch the exception that your app will crash and will be force closed. The user will not see what caused the crash, they will be shown a dialogue telling that the app has force closed unexpectedly and will give them the option to send a bug report. In this example if you were to look in the bug report you would see the error caused by java.lang.NullPointerException.

    Hope this helps.

提交回复
热议问题