如何调试onDestroy(),Android系统在调试器中暂停时会杀死应用程序 [英] How to debug onDestroy(), Android system kills app while paused in debugger

查看:130
本文介绍了如何调试onDestroy(),Android系统在调试器中暂停时会杀死应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试分析一个错误,该错误在按下后退按钮后调用Activity的onDestroy()方法时发生。我已经在有问题的代码中使用了断点(使用Eclipse)。调试器会在断点处暂停该应用,但Android系统也会将该应用从屏幕上移开,然后返回手机的主屏幕。应用暂停约10秒钟后,由于调试器突然断开连接,该应用的线程似乎已被Android系统破坏。

I have a bug I'm trying to analyze that occurs when the Activity's onDestroy() method is called after hitting the back button. I've put breakpoints in the offending code (using Eclipse). The debugger pauses the app at the breakpoint, but the Android system also takes the app off the screen and returns to the phone's homescreen. After the app is paused for about 10 seconds, the app's thread seems to get destroyed by the Android system because the debugger suddenly disconnects.

关于如何保留Android的任何想法系统从此执行?我需要保持该应用程序处于活动状态,以便我可以进入调试器,查看变量等。

Any ideas on how to keep the Android system from doing this? I need to keep the app alive so I can step in the debugger, look at variables, etc.

手机正在运行Android 2.3.5。

Phone is running Android 2.3.5.

推荐答案

我发现一种解决方法是将 startActivity()调用放入 onDestroy()(在 super.onDestroy()之前)启动活动的虚拟实例,只是为了保持应用程序的生命。 Android系统不会垃圾收集应用程序线程,因为其中仍在运行一个Activity(新的虚拟Activity)。这样一来,您就可以进行调试,因为调试器与线程的连接不会丢失。

A workaround that I found is to put a startActivity() call into onDestroy() (before super.onDestroy()) that starts a dummy instance of the Activity, just to keep the app alive. The Android system won't garbage collect the app thread because there is still an Activity running within it (the new dummy Activity). This in turn allows you to debug things because the debugger's connection to thread won't be lost.

如果手机弹出一个对话框,表明应用程序没有响应(强制关闭或等待),请不要单击等待,只需将其保留即可。似乎单击等待会导致应用线程被杀死,并为虚拟活动创建了新线程。

If the phone pops up a dialog saying the app is not responding (Force Close or Wait), don't click Wait, just leave it alone. It seemed that clicking Wait caused the app thread to be killed and a new thread was created for the dummy Activity.

这篇关于如何调试onDestroy(),Android系统在调试器中暂停时会杀死应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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