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

1
2
3
4
5
6
7
8
9
                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 );

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!

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.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 )

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 "up" phase for the back button instead. That will make your code work on all Android devices.

views:1725 update:2011/10/7 17:24:19
corona forums © 2003-2011