Android Hardware Buttons

Hi,

I am using the Key events in the latest SDK to try go back to the previous screen in the app that I am building. I am using the Director class to do a changescene when the back button is pressed.
But when The previous screen is getting displayerd all the images are getting distored and appear rectangular in shape.

The image of the problem is given here
https://picasaweb.google.com/111538299285179791683/August62011#

Is there anything specific that needs to be done to handle images when capturing the harware key press on Android phones.

The code that I am using is given below
[lua] local function onKeyEvent( event )
if event.phase == “up” and event.keyName == “back” then
director:changeScene( “Menu” )
end
return true
end

– Add the key callback
Runtime:addEventListener( “key”, onKeyEvent );

[import]uid: 50371 topic_id: 13411 reply_id: 313411[/import]

yeah I’m having the same problem except mines is a blank screen. I have the same code that you have.

I tried to clean up everything (with display.remove(obj), obj=nil) before director:changeScene( “Menu” ) but it didn’t work…

hmmm… something is fishy with director and key events!
[import]uid: 74346 topic_id: 13411 reply_id: 49637[/import]

Just as an update. I tried using the ChangeScene method in a timer function instead of calling it from the Key Event handler itself.
It solved the immediate problem of the images getting distorted.

I am not sure if it is a clean solution but seems to be working for me. [import]uid: 50371 topic_id: 13411 reply_id: 49685[/import]

hi, thanks for the update! that seemed to do the trick:

[lua]local function moveBack()
director:changeScene(“menu”)
end

local function onKeyEvent( event )
local returnValue = true

if (event.phase==“up” and event.keyName==“back”) then
timer.performWithDelay(100,moveBack,1)
end

return returnValue
end

– Add the key callback
Runtime:addEventListener( “key”, onKeyEvent )[/lua] [import]uid: 74346 topic_id: 13411 reply_id: 49694[/import]

Hello all,

The Samsung Galaxy Tabs won’t yield a key “up” event for the Back button if it is held for a second or longer. This is because the Galaxy Tab uses the Back button in conjunction with the power button to take screenshots. This is not a Corona bug and there isn’t anything we can do about this so.

So, I recommend that you use the key “down” phase for the back button instead. That will make your code work on all Android devices. [import]uid: 32256 topic_id: 13411 reply_id: 50957[/import]

@Joshua Quick: you state that there is a problem with using “up” with “back,” but then you recommend using “up.” Did I read your post right or am I missing something? [import]uid: 32178 topic_id: 13411 reply_id: 62901[/import]

Ack! Bad typos are bad. Fixed my post up above to indicate that you want to handle the “down” event, not the “up” event. Thanks jpot.

Also, the release version (#591) has a bug where modifying display objects within the key event Lua listener would cause an OpenGL error and make the screen go black. This includes modifying the screen via director. This bug was fixed in the newest daily builds. [import]uid: 32256 topic_id: 13411 reply_id: 62930[/import]