Breakpoints not hit while Debugging an AsyncTask in Eclipse for Android

May 1, 2012 03:10 by wjchristenson2

I ran into an issue yesterday where my breakpoints in an AsyncTask doInBackground method were not being hit.  After an hour of troubleshooting, I found two situations that can cause this issue.

1.  The doInBackground method is running before the Android debugger can attach to the process. Add the following to the beginning of your doInBackground method to see if this is the case.  If not, see cause 2 below.

 

@Override
protected Void doInBackground(Void... params) {
	android.os.Debug.waitForDebugger();
	
	// TODO Auto-generated method stub
	return null;
}

 

2.  An AsyncTask cannot execute another AsyncTask within the doInBackground method.  This was my problem.  An AsyncTask must be executed from the main (UI) thread.  So AsyncTask “A” cannot execute AsyncTask “B” in its doInBackground method as this is running on a background thread.

 

Bookmark and Share