Android的 - dismissDialog不关闭对话框对话框、Android、dismissDialog

2023-09-12 10:59:36 作者:风中的歌声

我现在用的是的ShowDialog() dismissDialog()来显示进度对话框在我的应用程序。从它创建对话框并调用显示(),以便使用该改变方向时,保存状态移动。

I am using the showDialog() and dismissDialog() to show progress dialogs in my app. Moved from creating the dialog and calling show() on it to using this in order to save state when changing orientation.

但是,当我改变从纵向状态> landscape->人像的方向, dismissDialog()不再关闭对话框。该对话框呆在那里所有的时间,我需要preSS后退按钮它消失了。

But when I change the orientation from portrait->landscape->portrait, the dismissDialog() no longer dismisses the dialog. The dialog stay there all the time and I need to press the back button for it to disappear.

任何理由为什么它会表现得这样?

Any reason why it would behave that way?

修改

要解决这个问题,我尝试添加一个 removeDialog()的onDestroy(),这样的对话是未创建/显示两次和方向改变之前,被删除的对话框。尝试添加日志语句,并看看会发生什么。

To overcome this issue, I tried adding a removeDialog() in onDestroy() so that the dialog is not created/displayed twice and before orientation change, the dialog is removed. Tried adding log statements and see what happens

05-21 12:35:14.064: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:14.064: DEBUG/MyClass(193): *************onCreareDialog

05-21 12:35:15.385: DEBUG/MyClass(193): *************onSaveInstanceState
05-21 12:35:15.415: DEBUG/MyClass(193): *************onDestroy

05-21 12:35:15.585: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:15.585: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:15.715: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:17.214: DEBUG/MyClass(193): *************onSaveInstanceState
05-21 12:35:17.214: DEBUG/MyClass(193): *************onDestroy

05-21 12:35:17.275: ERROR/WindowManager(193): android.view.WindowLeaked: Activity com.android.MyClass has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43362088 that was originally added here

05-21 12:35:17.395: DEBUG/MyClass(193): *************callingShowDialog
05-21 12:35:17.395: DEBUG/MyClass(193): *************onCreareDialog
05-21 12:35:17.475: DEBUG/MyClass(193): *************onCreareDialog

如果我们在这里看到,最初显示的活动时,该onCreateDialog被调用一次并改变方向,并的onSaveInstanceState的onDestroy调用。

If we see here, initially when the activity is displayed, the onCreateDialog is called once and on changing the orientation, onSaveInstanceState and onDestroy are called.

但在那之后,onCreateDialog被调用两次(通过调用的ShowDialog我做一次,而是为什么第二次?),并发生这种情况,每次我改变方向,因此第四。

But after that, onCreateDialog is called twice (once by a call to showDialog which I make, but why the 2nd time?) and this happens every time I change the orientation hence forth.

任何想法,为什么出现这种情况?

Any idea why that happens?

再次感谢

推荐答案

我终于找到了一个解决方案,工程 - 无需使用服务的

I finally found a solution that works - without the use of services.

这里的链接。希望它可以帮助别人。

Here's the link. Hope it helps someone.