Breakpoints not working with a service in Android

一曲冷凌霜 提交于 2019-12-10 18:39:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!