27

I'm running ADT (Android Development Tools) in Eclipse and verified that my debugger is working by putting a breakpoint in MainMenu.oncreate (class Activity). But when I put it in the first line of my AsyncTask.doInBackground, it never hits it. I know it's running because I put a Log statement in the AsyncTask and it shows up in LogCat. Any help would be appreciated as I prefer the debugger over the logging.

My versions:

Eclipse SDK Version: 3.6.1  
Build id: M20100909-0800

alt text

Phani Kumar Bhamidipati
  • 13,183
  • 6
  • 24
  • 27
Chirag Patel
  • 5,819
  • 8
  • 35
  • 38

2 Answers2

68

Put the following code fragment in the beginning of doInBackground:

android.os.Debug.waitForDebugger();

Then when you set a breakpoint in that thread, eclipse will find it.

sargas
  • 1,113
  • 12
  • 20
  • 1
    As a note, when **not** debugging I had to comment this line out in order for it to run. – Suragch Sep 05 '14 at 06:16
  • I can see that this is clearly the method to be able to do this, but I am not managing to hit the breakpoints even after putting this at the beginning of doInBackground. Does anyone have any idea why this might be? – James Meade Mar 18 '15 at 16:35
9

in addition to sargas's answer , because in Run mode you could get an error if you forget to comment that line, you could use the following:

if(android.os.Debug.isDebuggerConnected())
    android.os.Debug.waitForDebugger();

so it takes care of itself.

mihai71
  • 347
  • 4
  • 9