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
ShoulIClose = True ' This tells others to close
Activity.Finish
End If
Return True
Case Else
Return False
End Select
End Sub