断点不适用于Android中的服务 [英] Breakpoints not working with a service in Android

查看:126
本文介绍了断点不适用于Android中的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试我的服务,但由于断点不起作用,因此无法执行。是的,我使用过android.os.Debug.waitForDebugger(),无论在何处使用它(在该行之前,在onstartcommand中,在该方法中)都无效。我已设置断点,服务不会在它们处停止。我已经在正常活动中尝试了它们,它们在这里可以正常工作。

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.

推荐答案

在AndroidManifest.xml中添加属性 android:process =:sync 到服务条目:

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>

之后,以调试模式启动应用程序,并在加载后单击附加到进程按钮。
在列表中,您应该看到2个过程:

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

选择:sync一个,您就在做生意。

Select the :sync one and you are in business.

这篇关于断点不适用于Android中的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆