问题
I'm trying to debug my service but I'm unable to since breakpoints do not work. Yes, I have used android.os.Debug.waitForDebugger(), doesn't matter where I use it (before the line, in the onstartcommand, in the method) it doesn't work. I have my breakpoints set, the service does not stop at them. I have tried them on a normal activity, they work fine there.
回答1:
In AndroidManifest.xml add the property android:process=":sync" to the service entry:
<service
android:name=".SyncService"
android:exported="true"
android:process=":sync" >
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter"/>
</service>
After that start the application in debug mode and when it's loaded click the "Attach to process" button. In the list you should see 2 processes:
com.yourpackage
com.yourpackage:sync
Select the :sync one and you are in business.
回答2:
Have you tried printing log statements in your service to ensure that your service is even running?
Make sure you've declared your service in your manifest, that's a common error with making services.
来源:https://stackoverflow.com/questions/32302630/breakpoints-not-working-with-a-service-in-android