Back button not working on one page. Need some help.

Runtime back button listener isn’t working

When selecting ‘done’ on the android keyboard it isn’t pulling up the next text field

When submitting it registers with parse, but doesn’t change screens. 

I’m new to this so any help is greatly appreciated! Here is the page code.

___________________________________________________________

function scene:createScene( event )

    local group = self.view

–==============================Text functions============================–

    local function usernameListener( event )

        if ( event.phase == “began” ) then

            if(event.target.text == event.target.hintText) then

                event.target.text = ‘’

            end

        elseif ( event.phase == “ended” or event.phase == “submitted” ) then

            if(event.target.text == ‘’) then

                event.target.text = event.target.hintText

            else

                Usernametext = (event.target.text)

                native.setKeyboardFocus( passwordbox )

            end

        end

    end

    local function passwordListener( event )

        if ( event.phase == “began” ) then

            if(event.target.text == event.target.hintText) then

                event.target.text = ‘’

            end

            passwordbox.isSecure = true

        elseif ( event.phase == “ended” or event.phase == “submitted” ) then

            if(event.target.text == ‘’) then

                event.target.text = event.target.hintText

            else

                Passwordtext = (event.target.text)

                native.setKeyboardFocus( emailbox )

            end

        end

    end

    local function emailListener( event )

        if ( event.phase == “began” ) then

            if(event.target.text == event.target.hintText) then

                event.target.text = ‘’

            end

        elseif ( event.phase == “ended” or event.phase == “submitted” ) then

            if(event.target.text == ‘’) then

                event.target.text = event.target.hintText

            else

                Emailtext = (event.target.text)

                native.setKeyboardFocus( nil )                

            end

        end

    end        

–==============================Create Scene==============================—

    local usernamebox = native.newTextField(display.contentWidth*.5, display.contentHeight*.25, display.contentWidth*.75, 50)

    usernamebox.align = “center”

    usernamebox.text = “Username”

    usernamebox.hintText = ‘Username’

    usernamebox:addEventListener(“userInput”, usernameListener)

    local passwordbox = native.newTextField(display.contentWidth*.5, display.contentHeight*.4, display.contentWidth*.75, 50)

    passwordbox.align = ‘center’

    passwordbox.text = ‘Password’; passwordbox.hintText = ‘Password’

    passwordbox:addEventListener(“userInput”, passwordListener)

    local emailbox = native.newTextField(display.contentWidth*.5, display.contentHeight*.55, display.contentWidth*.75, 50)

    emailbox.align = ‘center’

    emailbox.inputType = ‘email’

    emailbox.text = ‘Email Address’; emailbox.hintText = ‘Email Address’

    emailbox:addEventListener( “userInput”, emailListener )

–===============Parse app information============—

    parse:init({ 

         appId = “X”, 

          apiKey = “X”

    })

    parse.showStatus = true

–=============create user listener===============–

    local function onCreateUser( event )

          print( event.response.createdAt )

          print( event.response.sessionToken )

    end

–=============create Parse User=================–

    local function onSubmitButton(event)

        if (“ended” == event.phase) then

            local userData = { [“username”] = Usernametext, [“password”] = Passwordtext, [“email”] = Emailtext }

            parse:createUser( userData, onCreateUser )

            storyboard.gotoScene( ‘menu’ , ‘fade’ )

        end

        return true

    end

–==================Submit data button==================–

    SubmitButton = widget.newButton

    {

        x = display.contentWidth*.5,

        y = display.contentHeight*.7,

        fontSize = 26,

        font = native.systemFont,

        id = “SubmitButton”,

        label = “Register”,

        onEvent = onSubmitButton

    }

–==============insert into group==========—

    group:insert( bg )

    group:insert(TitleLine)

    group:insert(Title)

end

function scene:enterScene( event )

        local group = self.view

end

function scene:exitScene( event )

        local group = self.view

        usernamebox:removeSelf( ); usernamebox=nil; Usernametext=nil

        passwordbox:removeSelf( ); passwordbox=nil; Passwordtext=nil

        emailbox:removeSelf( ); emailbox=nil; Emailtext=nil

        userData=nil

end

function scene:destroyScene( event )

        local group = self.view   

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )


return scene

I removed the back button function/runtime listener and have it running in my main.lua file now. Every page works properly except this one page. 

Found the issue to be related to how I am removing the native objects. When i remove the object:removeself() it goes back properly, but the objects are still on the screen.

native.* objects are not manageable from Storyboard.  They have to be removed by hand.

Rob

Rob,

    Is there guidance on properly removing by hand?

Whenever the scene changes, then storyboard executes exitscene() so I should be able to remove here, correct?

local usernamebox

enterscene()

usernamebox = native.newtextfield(x,x,x,x)

exitscene()

    if usernamebox then

        usernamebox:removeSelf(); usernamebox=nil

    end

I tried the above, but they aren’t being removed. I tried adding this to the next page, but still got nothing removed. 

Thanks for the help Rob. Got it working.

Moved the if true statements to the main.lua file that handles the storyboard change scene function. Back button is working properly now.

Only other issue I am having is setting the keyboard to move to the next textfield automatically once “submitted” or “ended”

native.* objects should be created in enterScene() and removed in exitScene().

Rob

Ok that makes sense… a lot easier to manage. Thanks!

I removed the back button function/runtime listener and have it running in my main.lua file now. Every page works properly except this one page. 

Found the issue to be related to how I am removing the native objects. When i remove the object:removeself() it goes back properly, but the objects are still on the screen.

native.* objects are not manageable from Storyboard.  They have to be removed by hand.

Rob

Rob,

    Is there guidance on properly removing by hand?

Whenever the scene changes, then storyboard executes exitscene() so I should be able to remove here, correct?

local usernamebox

enterscene()

usernamebox = native.newtextfield(x,x,x,x)

exitscene()

    if usernamebox then

        usernamebox:removeSelf(); usernamebox=nil

    end

I tried the above, but they aren’t being removed. I tried adding this to the next page, but still got nothing removed. 

Thanks for the help Rob. Got it working.

Moved the if true statements to the main.lua file that handles the storyboard change scene function. Back button is working properly now.

Only other issue I am having is setting the keyboard to move to the next textfield automatically once “submitted” or “ended”

native.* objects should be created in enterScene() and removed in exitScene().

Rob

Ok that makes sense… a lot easier to manage. Thanks!