I'm making a game and if the activity is left by the user (back or home key pressed), the activity needs to end the game by posting to a script and ending the activity.
I can detect if the back key is pressed, however, I cannot get any valid method to detect if the home key is pressed. I can't just end the game in the Activity_Pause method because let's say the user receives a phone call mid-game.
The Activity_Pause's UserClosed method returns false if home key is pressed. I tried using this code but no luck. Note that I'm not wanting to trap the home key event, just want to know if it was pressed when the Activity is paused.
I can detect if the back key is pressed, however, I cannot get any valid method to detect if the home key is pressed. I can't just end the game in the Activity_Pause method because let's say the user receives a phone call mid-game.
The Activity_Pause's UserClosed method returns false if home key is pressed. I tried using this code but no luck. Note that I'm not wanting to trap the home key event, just want to know if it was pressed when the Activity is paused.
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_HOME Then
Log("home")
awake.ReleaseKeepAlive
'Post to script to end game
Return False
End If
End Sub
Last edited: