简体   繁体   中英

Breakpoints not working with a service in Android

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM