A warning dialog is displayed but not displayed

I have an activity where I launch the built-in camera using onActivityResult. Having taken the picture, I return to my application and show a pop-up window asking the user whether he wants to take more pictures or not. It works fine, but after shooting, when I click the "Save" button on the camera’s built-in application, and on average, I click the "home" button. If I return to my application, my activity will be visible, but not active, there is a pop-up window that should be visible, but I do not see it. If I press the back button and cancel the pop-up, my activity is active again, but I do not want to allow the user to cancel the pop-up, so when this happens I can not use my application, I just need to kill it ...

The question is, how can I make the dialog always on top if it is displayed? The reason it seems that it is behind the activity, waiting for the user to interact with it ...

Thanks!

+2
source share
3 answers

The easiest way to find this is to track the lifetime of the dialog in action and do hide() / show() in onResume for activity. This solution only works for one Dialog at a time, but can be easily adapted to more if necessary.

1) Make your activity an implementation of Dialog.OnDismissListener .
2) Add an instance variable for the current Dialog in the Activity :

 private Dialog currentDialog = null; 

3) In onResume() add:

 if(currentDialog != null) { currentDialog.hide(); currentDialog.show(); } 

4) For each dialog box created in onCreateDialog() , add:

 dialog.setOnDismissListener(this); currentDialog = dialog; 

5) Finally, add:

 @Override public void onDismiss(DialogInterface dialog) { if(dialog == currentDialog) currentDialog = null; } 

I think this is fixed.

+3
source

Your dialogue seems to be canceled. Try dialog.setCanceleabe(false) and in onResume dialog.show() (to make sure it will be visible after activity resumes).

+1
source

An old question, I know, but you should add a headline: If the layout does not have a height or width, it can be reduced to 0 * 0 -> Invisible

0
source

Source: https://habr.com/ru/post/895646/


All Articles