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.
Asked
Active
Viewed 2,032 times
3
-
Are you starting your service in a separate process? if so, https://stackoverflow.com/a/62079516/1578867 may help. You'd need to attach to the process of the service at the appropriate time after it has started. – auspicious99 May 29 '20 at 05:57
2 Answers
4
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.

EZDsIt
- 921
- 1
- 9
- 14
-
This is just an example to start a service in a separate process. The name need not be just ":sync", but almost anything we would like. – auspicious99 May 30 '20 at 16:12
-1
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.

Chris Thoma
- 499
- 2
- 8
-
1Yes ofcourse, otherwise I wouldn't be debugging it. I have also checked, service also says debugger is attached. – SigmaO Aug 31 '15 at 03:33