调试服务 [英] Debugging a service
问题描述
我已经写了远程接口的服务,并在我的电脑的Eclipse的AVD安装了它。我有一个客户端的测试工具这将启动,并调用该服务的方法。最初,我有一个控制类和活动,我现在已经删除安装服务,使清单的服务如下:
I have written a service with a remote interface and installed it on my PC's Eclipse AVD. I have a client test harness which starts and invokes methods in the service. Initially I had the service installed by a control class and activity, which I have now removed, so that the manifest for the service looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myname.gridservice"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<service
android:enabled="true"
android:debuggable="true"
android:name="OverlayService">
<intent-filter>
<action android:name="com.myname.OverlayService.SERVICE"/>
<action android:name="com.myname.gridservice.IRemoteInterface" />
</intent-filter>
</service>
</application>
</manifest>
所以没有活动的标记。
so there's no activity tag.
当我启动它在Eclipse中调试图标,控制台告诉我这是在安装APK(它是),但它不会显示为一个调试线程断点不触发,尽管该服务的行为是确定只要客户看到它。如果我换行的服务标签,其中有一个关联类的活动标签,并启动了,那么我就可以调试它
When I launch it from the debug icon in Eclipse, the console tells me it's installing the apk (which it is), but it does not appear as a debug thread and breakpoints aren't triggered, although the service's behaviour is OK as far as the client sees it. If I wrap the service tag in an activity tag which has an associated class and launch that, then I can debug it
是否有可能不封装在一个活动调试服务?
Is it possible to debug the service without wrapping it in an activity?
推荐答案
这是我做的四个步骤:
第一:在你的服务的第一个有趣的方法(我用的创建):
First: In the first interesting method of your service (I used on create):
/* (non-Javadoc)
* @see android.app.Service#onCreate()
*/
@Override
public void onCreate() {
super.onCreate();
//whatever else you have to to here...
android.os.Debug.waitForDebugger(); // this line is key
}
第二:watiForDebuggerCommand后设置断点
Second: set break points after the watiForDebuggerCommand.
第三:通过在Eclipse中调试按钮启动应用程序。 (你或许应该已删除从清单中的主要活动推出到现在)
Third: Launch app via debug button in Eclipse. (You should probably have removed the main launch activity from the manifest by now)
最后:启动亚行和运行命令启动服务:
Last: Launch adb and run the command to start a service:
-
CD $ PLATFORM_TOOLS
-
亚行外壳
-
上午startservice -n com.google.android.apps.gtalkservice/com.google.android.gtalkservice.service.GTalkService$c$c>
cd $PLATFORM_TOOLS
adb shell
am startservice -n com.google.android.apps.gtalkservice/com.google.android.gtalkservice.service.GTalkService
这篇关于调试服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!