[英]Android: The AlertDialog is invisible when the Activity back to foreground
This question is related to The AlertDialog is invisible when the Activity back to foreground post. 这个问题与当Activity返回前台帖子时AlertDialog是不可见的有关。
I have the same problem. 我也有同样的问题。 The previous post is old, and have no answer. 以前的帖子很旧,没有答案。 Any suggestions how to solve that problem ? 有什么建议可以解决这个问题吗? Thanks... 谢谢...
For some reason, Dialogs' states must be handled by the developer. 由于某些原因,对话框的状态必须由开发人员处理。
Simply keep a reference to the dialog showing 只需保留对显示的对话框的引用
For example 例如
Dialog showingDialog=null;
Now in onResume() 现在在onResume()中
if(showingdialog!=null)
//show the dialog and maybe resume some state
Have you tried to re-display the AlertDialog when in the activities onResume(). 您是否尝试在活动onResume()中重新显示AlertDialog。 Using Google developers example you would be able to create an instance of this dialog and just recall it. 使用Google开发人员示例,您将能够创建此对话框的实例并进行调用。
http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog
Hope that helps. 希望能有所帮助。
Also we all create Dialogs on the fly whenever we need them, we should not. 同样,我们都在需要时即时创建对话框,我们不应该这样做。
Android way is (by the book ) to override an onCreateDialog(int) and showDialog(int) in our activities so that our dialogs can be managed by the activity lifecycle. Android的方法(按本书 )是在我们的活动中覆盖onCreateDialog(int)和showDialog(int) ,以便我们可以通过活动生命周期来管理对话框。
Another way to do so is to use myDialog.setOwnerActivity(MyActivity.this)
to tell the dialog it is managed by the activity. 这样做的另一种方法是使用myDialog.setOwnerActivity(MyActivity.this)
告诉对话框由活动管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.