Hi,
First off, I’m a Corona SDK beginner (just started 2 weeks ago) and I love how easy (except my problem :P) everything works! I’ve looked on the forum for post of people with similar but the ones I found couldn’t help me. I want to use device back button to control navigating through the scenes of my app. I’ve had a lot of help understanding how to tackle this issue using this post on the blog, but it still couldn’t help me.
Problem: whenever I press the back button on my device (HTC M8 mini) it crashes the app, returning it to my phone’s home screen with the message ‘testApp has stopped’. Although it does seem to work when pressing the back button in the main menu.
This is my scene/menu setup:
main - menu - vegScreen - productScreen
I use the following code in my main.lua:
function onDeviceDown( event ) local phase = event.phase local keyName = event.keyName if("back" == keyName and phase == "up") then if (storyboard.currentScene == "menu") then native.requestExit() else local lastScene = storyboard.returnTo if (lastScene) then storyboard.gotoScene(lastScene) return true else native.requestExit() end end end return false end Runtime:addEventListener("key", onDeviceDown)
In every lua file I set the destination of the back button using storyboard.returnTo = “menu” (or whatever screen/scene to return to) in the createScene function. With my current code, when I press the device’s back button in the productScreen or the vegScreen it results in my app crashing and returning the ‘testApp has stopped’ message.
I used the print function to check if the returnTo changes, which it does so there must me something wrong with onDeviceDown function, right?