警报对话框中显示,但不可见 [英] Alert dialog shown but not visible
问题描述
我有我的地方了内置摄像头使用的onActivityResult开始活动。拍摄照片后,我回到我的应用程序,并显示一个弹出要求用户如果他想拍摄更多的照片或没有。它工作正常,但在拍摄时,我preSS保存按钮,在内置摄像头的应用程序,并inmediatly我preSS home键,如果我回到我的申请,我的活动后可见,但不活跃,这应该是可见的弹出窗口是有,但我无法看到它。如果我preSS后退按钮和取消弹出,我的活动再度活跃,但我不想让用户取消弹出,所以,当出现这种情况,我不能用我的应用程序,我只需要杀死它...
I have an activity where I start the built-in camera using onActivityResult. After taking a picture, I go back to my application and show a pop up asking to the user if he wants to take more pictures or no. It works fine, but after taking the picture, when I press the "save" button on the built-in camera app, and inmediatly I press the home button, If I go back to my application, my activity is visible but not active and the popup that should be visible is there but I cannot see it. If I press the back button and cancel the pop up, my activity is active again, but I dont want to allow the user cancelling the pop up, so when this behavior occurs, I cannot use my app, I just have to kill it...
问题是,我怎么能强制对话框的顶部是始终如果显示?因为看起来它是活动的背后,等待用户与它交互...
The question is, how can I force to the dialog being always on the top if it is shown? Cause seems like it is behind the activity, waiting for the user to interact with it...
谢谢!
推荐答案
我已经找到解决这个问题的最简单的方法是跟踪在活动对话框的寿命和做一个隐藏()
/ 在
的活动。此解决方案仅适用于单个 onResume
显示()对话框
了一次,但可以很容易地适应更多的如果需要的话。
The easiest way I've found to fix this is to track the lifetime of the dialog in the activity and do a hide()
/show()
in the onResume
for the activity. This solution only works for a single Dialog
up at a time but could easily be adapted to more if required.
1)让您的活动实施 Dialog.OnDismissListener
。
2)在你的活动当前
:对话框
添加一个实例变量
1) Make your activity implement Dialog.OnDismissListener
.
2) Add an instance variable for the current Dialog
in your Activity
:
private Dialog currentDialog = null;
3) onResume()
补充:
if(currentDialog != null) {
currentDialog.hide();
currentDialog.show();
}
4)对于 onCreateDialog创建的每个对话框()
,地址:
dialog.setOnDismissListener(this);
currentDialog = dialog;
5)最后,添加:
5) Finally, add:
@Override
public void onDismiss(DialogInterface dialog) {
if(dialog == currentDialog)
currentDialog = null;
}
这似乎解决它为我。
这篇关于警报对话框中显示,但不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!