Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
If KeyCode = 4 Then ' you have pressed the back button
If OptionShowing Then ' Just an example flag to use
Close Options ' again just an example code
Return True ' Consume the event so that the app does not close
Else
Return False ' Do not consume so the app will close or go to the previous activity
End If
End If
End Sub