简体   繁体   English

Android:Activity返回到前台时,AlertDialog不可见

[英]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.

相关问题 Activity 回到前台时,AlertDialog 不可见 - The AlertDialog is invisible when the Activity back to foreground 在前景Android中的应用程序时如何显示AlertDialog? - How to show AlertDialog When Application in Foreground Android? 将活动放回前台时,startActivitySync会挂起 - startActivitySync hangs when putting an activity back to the foreground 当应用程序在 Android api 28(饼图)中处于前台或后台时,单击通知“启动活动”时的附加信息为 null - on click of notification "launching activity" has extras as null, when app is in foreground or back ground in Android api 28 (pie) 意图返回活动后,android alertdialog 不显示 - android alertdialog doesn't show after intent back to activity 启动活动时使 android 小部件不可见 - make android widget invisible when start activity 当具有“singleTask”launchMode的活动来到Foreground - Android时 - When an activity with “singleTask” launchMode comes to Foreground - Android 当应用重新回到前台时,Android AsyncTask和onResume - Android AsyncTask and onResume when the app is back in the foreground 停止 Android 服务(返回前台时)不起作用 - Stopping an Android service (when back to the foreground) not working Android服务和AlertDialog活动 - Android Service and AlertDialog Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM