Search code examples
androiddebuggingdalvik

Android: dalvik killing app due to ANR when in debugger breakpoint


On an Android 4.3 embedded (custom) device, I am trying to debug my app by setting a breakpoint in a Service sub-class onStartCommand method. When I am paused at the breakpoint dalvik kills my app due to ANR not realizing that I am debugging.

The logcat shows:

W/ANRWatchdog: An ANR was detected but ignored because the debugger is connected (you can prevent this with setIgnoreDebugger(true))
I/dalvikvm: threadid=3: reacting to signal 3
D/dalvikvm: threadid=1: still suspended after undo (sc=1 dc=1)
I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

Notice that I have an ANRWatchDog in my app which correctly recognizes the debug session and ignores the ANR.

Is theer a way to do the same with Dalvik? I am assuming it is possible to debug a Service without crashing due to ANR.


Solution

  • In developer settings, there is an option called "select debug app". Click on this and select the application you will be debugging. This should prevent any ANRs from occurring for that app, while you are debugging it. It also enables the "wait for debugger" option, which, if enabled, will pause the app as soon as it starts, so you can attach a debugger and debug the applications startup code, if necessary.