Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent ApplicationNotResponding during debugging

I am quite new to Android and have a debugging issue. I know what an ANR is for, and do not see them when I run my app normally. However, when I try to debug my BoradcastReceiver, I am too slow and get the ANR message.

Is there a way to switch off ANR during debug sessions? I could use log statement to see what's happening, but this is annoying....

edit: actually, I don't want to supress the ANRs in the LogCat, I want to tell android not to throw ANRs during debugging. I mean to allow Broadcast receivers to take longer than 5 seconds to run. But I guess it will not be possible and instead I should delegate to a service, which is allowed to run longer, which I also can debug easier.

Thanks in advance!

greets

like image 416
andreas Avatar asked Aug 19 '11 16:08

andreas


People also ask

How do you avoid ANR?

How to prevent an ANR? Stop doing heavy tasks on the main thread. Instead use worker threads such as IntentService, AsyncTask Handler, or another Thread simply.

Which of the following will trigger an ANR?

An ANR will be triggered for your app when one of the following conditions occur: While your activity is in the foreground, your app has not responded to an input event or BroadcastReceiver (such as key press or screen touch events) within 5 seconds.

What is ANR Responding time in Android?

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.


2 Answers

Go to Settings -> Developer options and check Show all ANRs.

This will show an App Not Responding dialog for apps running in the background. You can click the Wait button in the dialog to prevent the system from killing your process. Note that the dialog is opened automatically for apps running in the foreground. For background apps, you have to enable this option.

like image 140
Vicki Avatar answered Oct 03 '22 22:10

Vicki


No. This message is handled through the Android OS, not your application, and there is no way to hide it on the Emulator. If you don't want to see it and your BroadcastReceiver receives the call correctly, just doesn't run successful code, you can use a try-catch block, and instead of your application crashing, the catch will be handled, wherein you can make a Toast message or whatever you wish.

like image 36
Phil Avatar answered Oct 03 '22 23:10

Phil