Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- this goes to your main.lua
- local _IS_ANDROID, _IS_IOS
- if platform == 'Android' then
- _IS_ANDROID = true
- elseif platform == 'iPhone OS' then
- _IS_IOS = true
- end
- if _IS_ANDROID then
- Runtime:addEventListener('key', function (event)
- if event.keyName == 'back' and event.phase == 'down' then
- local scene = storyboard.getScene(storyboard.getCurrentSceneName())
- if scene and type(scene.backPressed) == 'function' then
- return scene:backPressed()
- end
- end
- end);
- end
- -- and this goes to your storyboard scenes
- function scene:backPressed()
- storyboard.gotoScene('scenes.menu', 'slideRight', 500) -- go to previous screen
- return true
- end
- -- But in your main menu scene you should ask the user if he wants to exit on back button press
- -- I have this code:
- function scene:backPressed()
- if not self.closeDialogShown then
- self.closeButton._view._onRelease()
- end
- return true
- end
- -- and close button in create scene:
- self.closeButton = widget.newButton{
- label = 'Exit',
- onRelease = function ()
- self.closeDialogShown = true
- native.showAlert('Exit?', 'ARE YOU SURE YOU WANT TO EXIT?', {'NO', 'YES'}, function (event)
- self.closeDialogShown = false
- if event.index == 2 then
- if _IS_ANDROID then
- native.requestExit()
- else
- os.exit()
- end
- end
- end}
- end}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement