简体   繁体   English

长时间运行时android应用程序挂起

[英]android app hangs when run for a long time

I have an Android app which listens to a port and updates the screen based on what it hears. 我有一个Android应用程序,可以监听端口并根据听到的内容更新屏幕。 This works flawlessly. 这可以完美地工作。 The problem happens when I leave the app running for say 20-30 mins. 当我让应用运行20-30分钟后,就会发生问题。 During this time the screen would have gone blank for power saving (display). 在此期间,屏幕将变黑以节省功率(显示)。 After this point, the app either becomes unresponsive or totally hangs. 此后,该应用程序变得无响应或完全挂起。 I doubt if it's memory leaks. 我怀疑是否是内存泄漏。 Can't figure out how to go about debugging this issue. 无法弄清楚如何调试此问题。 Any pointers? 有指针吗? TIA TIA

May be there are variables that are lost, try to save and restore the state of your Activity using the methods onSaveInstanceState() and onRestoreInstanceState() . 可能有丢失的变量,请尝试使用onSaveInstanceState()onRestoreInstanceState()方法保存和恢复您的Activity状态。

check https://stackoverflow.com/a/151940/1434631 检查https://stackoverflow.com/a/151940/1434631

I was building a widget for android and same thing was happening to me. 我正在为android构建小部件,同样的事情也在发生。 I believe the problem is that process is destroyed and started again from time to time, and then all your variables lose value. 我相信问题在于,该过程有时会被破坏并重新启动,然后所有变量都会失去价值。 You should use content provider to store them and then obtain them when lost. 您应该使用内容提供程序来存储它们,然后在丢失时获取它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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