使用带有线程的 ProgressDialog 时,应用程序因方向更改而崩溃
-->我在第一个活动中实现了线程。并还使用了进度对话框。所以现在在方向(仅该屏幕)期间我的应用程序崩溃 - 给出内存泄漏的异常。作为这个问题的解决方案,我从这里才知道我应该把
android:configChanges="keyboardHidden|orientation"
但现在我的该活动的 onCreate() 方法没有被调用,我有必要在orientationChanges上调用这个方法。那么这个阶段我应该做什么呢?
--> I've implemented threading in my first activity. And made the use of progress dialog also. So now during the orientation (of that screen only) my application crashes - gives exception of memory Leaked. And as a solution of this I came to know from here only that I should put
android:configChanges="keyboardHidden|orientation"
But now my onCreate() method of that activity is not getting called, and it is necessary for me to call this method on orientationChanges. So what should I do at this stage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看此博客:
http: //blog.doityourselfandroid.com/2010/11/14/handling-progress-dialogs-and-screen-orientation-changes/
还有其他类似的问题在 stackoverflow 上:
如何处理进度时屏幕方向的变化对话框和后台线程处于活动状态?
如果使用第一个选项,我遇到过模拟器有一个错误,导致它调用 onCreate() 两次 - 导致崩溃,但这在真实环境中不应该是问题设备。
Check out this blog:
http://blog.doityourselfandroid.com/2010/11/14/handling-progress-dialogs-and-screen-orientation-changes/
There are also other similar questions here on stackoverflow:
How to handle screen orientation change when progress dialog and background thread active?
I have experienced, if using the first option, that the emulator has a bug which makes it call onCreate() twice - causing a crash, but it shouldn't be an issue on a real device.
将其添加到您的清单文件
示例中:
Add this to your manifest file
example :
您真的想处理应用程序的方向更改吗?
如果没有,您可以在manifest.xml 文件中设置
screenOrientation
属性,这样无论手机的方向如何,您的应用都会保持该方向。如果这样做,您应该重写此方法
public void onConfigurationChanged (Configuration newConfig)
,在这里您可以处理应用程序的配置(方向、键盘隐藏等)更改。如果您不覆盖此设置,系统将简单地关闭您的应用程序并重新启动它。这会导致内存泄漏。Do you really want to handle the orietation changes for you app?
If not, you can set the
screenOrientation
attribute in the manifest.xml file, so your app will keep in that orientation, no matter how your phone's orientation is.If you do, you should override this method
public void onConfigurationChanged (Configuration newConfig)
, here you can handle the configure(orientation, keyboard hidden, etc) changes for you app. If you don't override this, the system will simply shutdown you app and restart it. This would result in memory leakage.