Many android phones including my Samsung Note have a Back Button.
What is the method used to detect this button? I want a sub routine to be called when user presses that button...
Thanks
Sub Globals
Dim closeCounter As Int ' For double click exit routine
Dim closeTimer As Long
end sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Select KeyCode
Case KeyCodes.KEYCODE_BACK
closeCounter = closeCounter + 1 ' Handle the user exit request
' First time so start the counter
If closeCounter = 1 Then
closeTimer = DateTime.Now
ToastMessageShow("Press Back again to exit", False)
End If
' Second time but not within 3 seconds, reset to "First time"
If closeCounter = 2 AND DateTime.Now > closeTimer + 3000 Then
closeCounter = 1
closeTimer = DateTime.Now
ToastMessageShow("Press Back again to exit", False)
End If
' Two tries within 3 seconds, we're done
If closeCounter = 2 Then
closeCounter = 0
Activity.Finish
End If
Return True
Case Else
Return False
End Select
End Sub
Please post your Activity_Press code.
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("Are you sure to exit?", "", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Return False
ExitApplication '...or whatever other previous killing actions.
Else
Return True
End If
End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("Are you sure to exit?", "", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Return False
ExitApplication '...or whatever other previous killing actions.
Else
Return True
End If
Else
Return False ' Handle the other presses in the OS
End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If Msgbox2("Are you sure to exit?", "", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Return False
ExitApplication 'THIS CODE WILL BE NEVER EXECUTED JUST RETURN FALSE AND THE ACTIVITY WILL STAY ALIVE
Else
Return True
End If
Else
Return False ' Handle the other presses in the OS
End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Select KeyCode
Case KeyCodes.KEYCODE_BACK
closeCounter = closeCounter + 1 ' Handle the user exit request
' First time so start the counter
If closeCounter = 1 Then
closeTimer = DateTime.Now
ToastMessageShow("Press Back again to exit", False)
End If
' Second time but not within 3 seconds, reset to "First time"
If closeCounter = 2 AND DateTime.Now > closeTimer + 3000 Then
closeCounter = 1
closeTimer = DateTime.Now
ToastMessageShow("Press Back again to exit", False)
End If
' Two tries within 3 seconds, we're done
If closeCounter = 2 Then
closeCounter = 0
Activity.Finish
End If
Return True
Case Else
Return False
End Select
End Sub