避免对话框Android的最佳途径设备旋转后驳回对话框、途径、设备、Android

2023-09-12 04:48:42 作者:我不蛇蝎怎能毁你所爱

在解决这个论坛很长的搜索,我发现很多的答案,人们提出使用方案,以避免对话旋转后辞退,就像:

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的参考文档后,我会注意到,这些对话的方法被去precated。

But, after look around the Android Reference Documentation, I could notice that these Dialog methods are being deprecated.

因此​​,一个显而易见的问题是:

So, the obvious question is:

今天,什么是避免对话框的设备旋转后驳回最好的方法是什么?的

在此先感谢。

推荐答案

您现在应该使用的 DialogFragment 新片段的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.