Android Studio - Debug into AsyncTask / IntentService

To the point:

Using Eclipse
I'm having no issue setting a breakpoint in an IntentService in my project and having it hit.

Using Android Studio
The same project (I'm able to run it from both Eclipse and AS) I can set breakpoints in some places (an Activity, for example) and it will hit, but it will not hit in other locations - an IntentService, for example.  It won't even validate the breakpoint.  What gives?

This is preventing me from moving to AS permanently.

Comment actions Permalink

For me the breakpoint inside onHandleIntent() work correctly. Could you please attach your AndroidManifest.xml file? Possibly your service works in different process, then you should use "Attach debugger to Android process" action to make it work

Comment actions Permalink

My pleasure.  Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET"/>

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        <service android:enabled="true" android:name=".services.RESTService" android:permission="android.permission.INTERNET"></service>
        <activity android:name="ResultActivity"></activity>


For what it's worth, I also tried to "attach to process" and got this:

Error running Android Debugger (8620)
Unable to open debugger port : "handshake failed - connection prematurally closed"

But, again, I do see breakpoints in my Activity being hit so...

Comment actions Permalink

Where do you put breakpoint in the service exactly? Don't you see the cross on the top of it after the debugger connected?

Comment actions Permalink

I've placed a breakpoint at several places, including just a few lines inside onHandleIntent:

ParcelUuid requestID = intent.getParcelableExtra(EXTRA_UNIQUE_ID);

When the debugger connects, I see the breakpoints in one of my Activities get a checkmark, and those are the breakpoints that will hit.  Breakpoints I've set in the super class of that Activity (I've extended Activity, and my Activity extendeds that) do not get the checkmark, nor do the breakpoints in the service.  And, of course, none of the unchecked breakpoints hits.

Comment actions Permalink

FWIW, I've also tried this with an AsyncTask and no luck.  I'm sure people are doing this, and i'm able to do this with other IDEs, so I know it's doable.  Maybe I'm missing something very basic?

Comment actions Permalink

Maybe you can tell me what steps you go through to set and hit a breakpoint in either an AsyncTask, or an IntentService, as I have no luck with either one.  Do I have to do something special to the manifest, set some special attribute somewhere?

Comment actions Permalink

It is weird that you're not able to attach debugger to the running process. As I understand, you launch your run configuration by "Debug" action, don't you? Please try to do it without setting any break points and make sure that the debugger is fully connected. Try to press "Pause" button, then try to add some breakpoints in the places they work for you and make sure that debugger can stop there several times (for example after stopping press F9 again and relaunch the activity on the device). Also make sure that your APK is NOT obfuscated (by ProGuard), it may causes the problems for debugger. ProGuard can be enabled/disabled in Android facet settings or the settings of some Android artifact.

Comment actions Permalink

While I don't know to what I should atribute the change, this is now working.  I haven't done anything different, although I have been upgraded through several different versions to, now, AI-130.729444.  Maybe that's the difference?  In any case, thanks for sticking with me!


Please sign in to leave a comment.