How to consume back button without Msgbox Modal?

ozgureffe

Member
Licensed User
Longtime User
I have a program. And I want my own modal boxes in it...

And i want to consume KeyCodes.KEYCODE_BACK when one of my modals is open.

While one of my modal windows is visible I want back button to hide my modal only.

While using MsgBox or MsgBox2 Modals it works as it expected.

But with my modals(not real modals, only semi-transparent background panels to cover activity and texts, buttons etc.) it hides my modal panel first then it doesn't Return.False. It goes on and exits the activity.

I checked everything related consuming events on the forum. But couldnt find the correct way. Is that possible or is there any restriction related with android OS?


B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean

    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If ModalDialog.Visible Then
            ModalDialog.Visible = False 'Hide modal only
            Return False 'and dont go further
        Else
            Return True 'do like what normal back_button do 
        End If
    End If

End Sub
 
Top