Android-避免设备旋转后关闭对话框的最佳方法 [英] Android - Best way of avoiding Dialogs to dismiss after a device rotation
问题描述
在这个论坛上进行了长时间搜索之后,我发现了很多答案,人们建议使用解决方案来避免对话框旋转后消失,就像:
After a long search around this forum, I found a lot of answers where people propose using solutions for avoiding dialogs to dismiss after rotation, just like:
android:configChanges="keyboardHidden|orientation"
或重写似乎是最推荐的以下方法:
Or override the following method, which appeared to be the most recommended:
protected Dialog onCreateDialog(int id)
但是,浏览一下Android参考文档后,我会发现不建议使用这些Dialog方法.
But, after look around the Android Reference Documentation, I could notice that these Dialog methods are being deprecated.
因此,显而易见的问题是:
So, the obvious question is:
今天,避免设备旋转后关闭对话框的最佳方法是什么?
谢谢.
推荐答案
您现在应该使用 DialogFragment 来自新的Fragments API.要在低于3.0的平台上使用它,请使用兼容性软件包.
You should now use DialogFragment from new Fragments API. To use it on the platform lower, than 3.0, use compatibility package.
这篇关于Android-避免设备旋转后关闭对话框的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!