android hardware back button doesn't work

I am trying to use hardware back button as  back button of app.in my main.lua ,

local storyboard=require(“storyboard”);

Runtime:addEventListener(“key”, function (event)

        if(event.keyName == “back” and event.phase == “down”) then

           local scene = storyboard.getScene(storyboard.getCurrentSceneName())

           

            return scene:backPressed()

            

        end

    end); 

in option.lua ,

function scene:backPressed()

    storyboard.gotoScene(“start_menu”,{

        effect=“crossFade”,

        time=250

        });

    return true

end

it should go back to start_menu page from the option page .

it causes hang and after a while  exit from the app .but app’s back button works fine from option.lua. I don’t understand what’s the problem .please help

You need to detect ‘up’ & ‘down’ phases too.

local phase = event.phase local keyName = event.keyName if ( "back" == keyName and phase == "up" ) then -- Do you stuff there end

You need to detect ‘up’ & ‘down’ phases too.

local phase = event.phase local keyName = event.keyName if ( "back" == keyName and phase == "up" ) then -- Do you stuff there end