Android Back Button

I’ve tried to close my app by using the back button on Android. In the game.input_binding file, I mapped Back to KEY_BACK. In my code I check for action_id = hash(“KEY_BACK”) and using msg.post("@system:", “exit”, {code = 0}). It doesn’t fire using the Android back button. For fun, I mapped another key to KEY_BACK and (using a keyboard) when I press that key, I get the desired effect. I’m about to go mad. Would someone point me in the right direction? Thanks

Strange. I’m doing something similar, but am mapping both “Back” and “Esc” to the action id. I think Android should only need that “Back” mapped, though.

Simplified code here from my project.

local BACK_BUTTON = hash("back_button")

function on_input(self, action_id, action)
	if action_id == BACK_BUTTON and action.pressed then
		sys.exit(0)
		return true
	end
end

On a side note, I think the best-practice to exit is calling sys.exit(0), instead of that message.

4 Likes