将Eclipse调试器附加到重新启动的应用程序

时间:2021-08-01 20:53:58

I am testing the onsave/onrestore mthods of my android application.

我正在测试我的android应用程序的onsave/onrestore mthods。

To do this I phone my device and see that it kills the process and then I hang up. :) I see that it restarts the application.

为了做到这一点,我给我的设备打电话,看到它杀死了这个过程,然后我挂断了电话。我看到它重新启动了应用程序。

Question is: how do I cause it to restart in debug mode so I can step through the restore process? Is there a way to tell it to automatically attach to the debugger when starting up?

问题是:如何使它在调试模式下重新启动,以便我能够逐步执行恢复过程?是否有方法告诉它在启动时自动附加到调试器?

4 个解决方案

#1


9  

Use android.os.Debug.waitForDebugger();

使用android.os.Debug.waitForDebugger();

Basically, start via debugging. Exit out of your app. Set some break points. Enter back into your app (make sure that this line is hit, so put it in your onCreate or somewhere else) and it will re-attach to the running debugger.

基本上,通过调试开始。退出你的应用。设置一些断点。重新输入你的应用程序(确保这条线是命中的,所以把它放在你的onCreate或其他地方),它会重新连接到正在运行的调试器。

#2


1  

I don't think there is a way to ensure the app restarts in debug mode. But if you are debugging your own app and don't mind adding debug code for testing you might want to add a Thread.sleep(5000) or something like this at an appropriate place in your startup methods. This should give you enough time to reconnect the debugger via the DDMS. Remove when you are done, of course ;)

我认为没有办法确保应用程序在调试模式下重新启动。但是,如果您正在调试自己的应用程序,并且不介意为测试添加调试代码,那么您可能需要在启动方法的适当位置添加一个Thread.sleep(5000)或类似的东西。这将给您足够的时间通过DDMS重新连接调试器。当然,当你完成的时候就可以删除;)

#3


1  

There is a configuration option in Android settings > developer options > debugging > select app to be debugged. What it does is calling the eclipse debugger every time certain application is opened, if it's connected to the adb and the app's project is open.

在Android settings > developer options > debug > select app中有一个配置选项要调试。它所做的就是每次打开某个应用程序时都调用eclipse调试器,如果它连接到adb并打开应用程序的项目。

#4


0  

Programmatically: Use waitForDebugger(). Documentation here.

以编程方式:使用waitForDebugger()。这里的文档。

Note that the method returns as soon as the debugger attaches, so it's best practice to place a breakpoint right after that call. Additionally, you can test the debugger attachment status using isDebuggerConnected().

注意,调试器一旦加载,该方法就会返回,因此最好在调用之后放置断点。此外,您可以使用isDebuggerConnected()测试调试器附件状态。

In Eclipse: Open the DDMS perspective of eclipse, select the freshly-restarted app on your device, and then select the debug option. This will attach the debugger to the restarted instance.

在Eclipse中:打开Eclipse的DDMS透视图,选择设备上重新启动的应用程序,然后选择debug选项。这将把调试器附加到重新启动的实例。

On the Device: There is a configuration option under some* handsets that allows you to select an app to be debugged when USB debugging is configured. It's under the Developer Options in your device settings. This will attach the debugger automatically.

在设备上:在某些*手持设备下有一个配置选项,允许您在配置USB调试时选择要调试的应用程序。它在你的设备设置中的开发者选项下。这将自动附加调试器。

*For example, my Galaxy S4 has it, my HTC Rezound does not. I believe it might be a Jelly Bean specific option.

*例如,我的Galaxy S4有,我的HTC Rezound没有。我相信这可能是一个果冻豆的具体选择。

#1


9  

Use android.os.Debug.waitForDebugger();

使用android.os.Debug.waitForDebugger();

Basically, start via debugging. Exit out of your app. Set some break points. Enter back into your app (make sure that this line is hit, so put it in your onCreate or somewhere else) and it will re-attach to the running debugger.

基本上,通过调试开始。退出你的应用。设置一些断点。重新输入你的应用程序(确保这条线是命中的,所以把它放在你的onCreate或其他地方),它会重新连接到正在运行的调试器。

#2


1  

I don't think there is a way to ensure the app restarts in debug mode. But if you are debugging your own app and don't mind adding debug code for testing you might want to add a Thread.sleep(5000) or something like this at an appropriate place in your startup methods. This should give you enough time to reconnect the debugger via the DDMS. Remove when you are done, of course ;)

我认为没有办法确保应用程序在调试模式下重新启动。但是,如果您正在调试自己的应用程序,并且不介意为测试添加调试代码,那么您可能需要在启动方法的适当位置添加一个Thread.sleep(5000)或类似的东西。这将给您足够的时间通过DDMS重新连接调试器。当然,当你完成的时候就可以删除;)

#3


1  

There is a configuration option in Android settings > developer options > debugging > select app to be debugged. What it does is calling the eclipse debugger every time certain application is opened, if it's connected to the adb and the app's project is open.

在Android settings > developer options > debug > select app中有一个配置选项要调试。它所做的就是每次打开某个应用程序时都调用eclipse调试器,如果它连接到adb并打开应用程序的项目。

#4


0  

Programmatically: Use waitForDebugger(). Documentation here.

以编程方式:使用waitForDebugger()。这里的文档。

Note that the method returns as soon as the debugger attaches, so it's best practice to place a breakpoint right after that call. Additionally, you can test the debugger attachment status using isDebuggerConnected().

注意,调试器一旦加载,该方法就会返回,因此最好在调用之后放置断点。此外,您可以使用isDebuggerConnected()测试调试器附件状态。

In Eclipse: Open the DDMS perspective of eclipse, select the freshly-restarted app on your device, and then select the debug option. This will attach the debugger to the restarted instance.

在Eclipse中:打开Eclipse的DDMS透视图,选择设备上重新启动的应用程序,然后选择debug选项。这将把调试器附加到重新启动的实例。

On the Device: There is a configuration option under some* handsets that allows you to select an app to be debugged when USB debugging is configured. It's under the Developer Options in your device settings. This will attach the debugger automatically.

在设备上:在某些*手持设备下有一个配置选项,允许您在配置USB调试时选择要调试的应用程序。它在你的设备设置中的开发者选项下。这将自动附加调试器。

*For example, my Galaxy S4 has it, my HTC Rezound does not. I believe it might be a Jelly Bean specific option.

*例如,我的Galaxy S4有,我的HTC Rezound没有。我相信这可能是一个果冻豆的具体选择。