NativeMessageBox::showMessageBoxAsync on Android is not topmost

When you use NativeMessageBox::showMessageBoxAsync it pops the window on top of other components.
However if you now click outside the messagebox window itself, the other component will obscure the messagebox and there is no way to get to the messagebox window anymore since its obscured.

Is there any way to prevent this from happening? Ideally message boxes should be always on top of all other windows. I understand that Android doesn’t have modal behavior but this is a major usability issue if messageboxes can get hidden from the user by accidentally clicking somewhere else!

The messagebox is not hidden, it’s being dismissed. But in any case, there is a JUCE bug: dismissing the callback this way will never trigger the Callback in NativeMessageBox::showMessageBoxAsync. I’ve fixed this now on develop with commit d4e0ba0. As it’s a change in java land, you’ll need to re-save your project with the Projucer. I did this for all the JUCE example projects (commit ede622c).

Thanks Fabian. Yeah the callback was not being called. When its dismissed what is the default option selected for the messagebox and can it be specified? i.e. in a YesNo messagebox it should be No.
Will try out the fix.

Yes that’s exactly what it will do.

Hi Fabian,

I merged in your fix but it still doesn’t invoke the callback. We do this:

juce::NativeMessageBox::showYesNoBox(m_iconType, m_title, m_message, m_pMain,
ModalCallbackFunction::create( MessageBoxMessageCallback, this) );

In android studio I see it calling the java function showOkCancelBox (it has your changes) but when you click outside the message box none of the onClick handlers get called. As a result it never executes the alertDismissed function with the callback.

Ahh you need to re-save your project with the Projucer for my change to have any effect (the Projucer copies the changed java files into your project when you save your jucer file).

This is the change that will call your callback when the MessageBox is dismissed:

Hi Fabian,

Yes I have re-saved the project from the Projucer after including your changes. I also verified in the debugger that it was indeed seeing the new code. The problem is that the onCancel call itself in the code you quoted above is never invoked when you click outside the dialog. It does get called when you click the cancel button.

I am running on a Pixel device with Android-O if that is relevant.

Yeah tested this in the emulator with Android O and seems to work fine for me. Let me test this on a real device…

EDIT: yes, also works for me on a Nexus 5X with Android M

My bad sorry. We had some local changes to that file so I missed merging in your code for the setOnCancelListener implementation. Thats why the callback wasn’t called. doh!
Sorry about that. It works now. Thanks