android device back key event not triggered

Hi all,

i have been trying to use the back key event of the android device button ,  i have looked every where but the event simply is not triggered .

 local function onKeyEvent( event ) local phase = event.phase local keyName = event.keyName if(keyName=="back") then print("Back event is working") end -- we handled the event, so return true. -- for default behavior, return false. return true end -- Add the key callback Runtime:addEventListener( "key", onKeyEvent );

i tried to test this code over and over but nothung is happening

That should work. For testing purposes, try changing 

 if(keyName=="back") then

to

 if(keyName=="b") then

and then when running in the simulator, press the b button on your keyboard and see if the print statement appears.

You don’t by any chance have 2 key listeners running which are conflicting with each other do you?

yeah i already tried that and its working … but the back event is not triggered … i thought it has something to do with the simulator so i tried it on a device and still not working !!!

yeah i don’t … thats the only key listener am using

That should work. For testing purposes, try changing 

 if(keyName=="back") then

to

 if(keyName=="b") then

and then when running in the simulator, press the b button on your keyboard and see if the print statement appears.

You don’t by any chance have 2 key listeners running which are conflicting with each other do you?

yeah i already tried that and its working … but the back event is not triggered … i thought it has something to do with the simulator so i tried it on a device and still not working !!!

yeah i don’t … thats the only key listener am using