I have a noobe question. If I use this code to trap a BACK keypress it will always present the Exit Program messagebox to the user...
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("Exit Program?", "EXIT", "Yes", "", "No", Null) =DialogResponse.POSITIVE Then
activity.finish
Else
Return True
End If
End If
End Sub
Problem:
The BACK button is also used to withdraw out of child displays, like a menu or help panel. When the above code is used, while at a child level, the effect is to ask the user if they wish to exit the program, when the correct process is to close the child display and return to the base level of the program.
How do we allow the BACK button to withdraw from child displays but STILL be able to ask the user 'exit program' when at the base parent level of the program? Because the above routine ALWAYS intercepts the BACK button whatever program level is displayed.
I tried using a boolean variable that kept track of whether the program was at the base level or in a child display level. I added:
If PROGRAMBASE = False Then Return True 'not at the base level so don't ask about exiting
to the start of the above routine. This simply stopped the BACK button from working in its normal backing-out process when not at the base parent level.
It seems you can not have the BACK button perform both functions: for backing out from a child display and for a friendly exit messagebox.
Any ideas?
[Note on the code: I used Erel's code but found it didn't work so I changed his 'Return False part to 'activity.finish', and now the messagebox part works.]