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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With