Reputation: 730
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...
Thanks!
Upvotes: 4
Views: 3987
Reputation: 21
Old question, I know, but you should add a title: If the layout does not have a height or width it can get downscaled to 0*0 -> Invisible
Upvotes: 1
Reputation: 8242
Seems your dialog is cancelable. Try dialog.setCanceleabe(false)
and in onResume
dialog.show()
(for assuring that it will be visible after resuming activity).
Upvotes: 1
Reputation: 46
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) Make your activity implement Dialog.OnDismissListener
.
2) Add an instance variable for the current Dialog
in your Activity
:
private Dialog currentDialog = null;
3) In onResume()
add:
if(currentDialog != null) {
currentDialog.hide();
currentDialog.show();
}
4) For each dialog created in onCreateDialog()
, add:
dialog.setOnDismissListener(this);
currentDialog = dialog;
5) Finally, add:
@Override
public void onDismiss(DialogInterface dialog) {
if(dialog == currentDialog)
currentDialog = null;
}
That seems to fix it for me.
Upvotes: 3