Need help with native.showalert()

The alert shows and dismisses ok, but when another button is touched the alert is back.

What am I doing wrong?
Hopefully some extra eyes can tell me.

Code as below is in file bdlogin.lua which is included in main.lua
A Login button in titlebar in main.lua calls the gotoLogin function in bdlogin.lua.

Works perfectly in simulator.
Works perfectly on device if alert is commented out, I.e. screen change correctly when Login or Back buttons pressed.

With alert in use and on device the alert pops up when changing to loginScreen.
On dismiss (OK touch) the alert dismisses.
Now for the yukk…
When the back button is touched the alert pops back up and the loginScreen redisplays instead of the slide to coffeeListScreen. I.e. it never goes back, just reactivates the alert and re-slides to loginScreen.

Please tell me where I’m screwing up. It’s been driving me nuts as I have similar working on other pages and the sample fish app with alert works.

Of course my normal bdlogin.lua contains more code but I’ve trimmed it down in an effort to find my own mistakes, but have failed :slight_smile:

TIA

[lua]-- bdlogin.lua

– in main.lua
– require(“bdlogin”)
– coffeeListScreen = newScreen( 320, true, “Rare Parts”, “stripes”, false, “redtitlebg.png”, nil, nil, 320, 1024 )
– coffeeListScreen:addRightButton( “Login”, gotoLogin, false, nil, nil, nil, nil, “redbtnleft.png”, “redbtnmid.png”,“redbtnright.png”, “custombtnleft-over.png”, “custombtnmid-over.png”, “custombtnright-over.png” )

– loginScreen = newScreen( 320, true, “Account Login”, “stripes”, true, “redtitlebg.png” )
– loginScreen:addLeftButton( “”, goBackToFirstFromLogin, false, “redbackbtn.png”, “custombackbtn-over.png” )
– *******************************
goBackToFirstFromLogin = function (event )
if event.phase == “release” then
loginScreen:slideToRight( coffeeListScreen )
end
end

gotoLogin = function()
local function onComplete( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
– Do nothing; dialog will simply dismiss
end
end
end
local alert = native.showAlert( “Corona”, “Alert test”, { “OK” }, onComplete )
coffeeListScreen:slideToLeft( loginScreen )
end[/lua] [import]uid: 6547 topic_id: 10180 reply_id: 310180[/import]

Hey there :slight_smile:

Go;
CoronaSDK/SampleCode/Interface/Alert

Check out that sample app to see how native alerts are typically handled.

Peach :slight_smile: [import]uid: 52491 topic_id: 10180 reply_id: 37271[/import]

That’s what I did and that’s where most of the code comes from.

However, some changes were needed, mainly from placing alert at beginning of app to somewhere in the middle and in another file.

Note also, works elsewhere in similar situation, but not in above.

A pair of knowledgeable eyes will hopefully tell me where I went wrong, I.e. typo, usage, etc.

Thanks for trying, always appreciated.

Heinz [import]uid: 6547 topic_id: 10180 reply_id: 37295[/import]

Even though I have a work-around in use in my App I’m still fussing with this.

I’ve come to a possible scenario… Once I dismiss the alert the back ground becomes ‘hot’ and when touched the page reloads, alert re-appears, etc. etc.

Not using any such events, intentionally at least. Back to examining code. [import]uid: 6547 topic_id: 10180 reply_id: 37307[/import]

Finally…

If I call my login function via button press or release, all is well. I.e. gotoLogin()

If I call it via [lua]addRightButton( “Login”, gotoLogin, false, nil, nil, nil, nil, “redbtnleft.png”, “redbtnmid.png”, “redbtnright.png”, “custombtnleft-over.png”, “custombtnmid-over.png”, “custombtnright-over.png” )[/lua]

it goes nuts. I.e. background becomes ‘hot’, alert never goes away, screen reloads.

Did I screw up my syntax for the addRightButton? Been looking at this stuff for so long now, could easily happen.

Heinz

I tried a ‘once removed’ I.e.
[lua]local function gotoLoginPage()
gotoLogin()
end

coffeeListScreen:addRightButton( “Login”, gotoLoginPage, false, nil, nil, nil, nil, “redbtnleft.png”, “redbtnmid.png”, “redbtnright.png”, “custombtnleft-over.png”, “custombtnmid-over.png”, “custombtnright-over.png” )[/lua]
No diff, still misbehaves. Oh well, at least now I know :slight_smile:

UPDATE: Not as cut and dries as first thought. Still narrowing it down. Probably as first suspected, user error… but still looking for the ‘where’.
Will report once found in case it might help some other soul of going through my hell :slight_smile:

[import]uid: 6547 topic_id: 10180 reply_id: 37314[/import]

Last update… case closed.

Not ‘exactly’ sure where I went wrong because I ripped a lot of stuff apart. One of the drawbacks of my trial-and-error-programming style.

The end consensus though is that I had screwed up checking event results between keyboard and/or button. Between may be the wrong term but it was one or the other as I was trying to terminate input on a button release and also on keyboard return key press.

I’m back to using addRightButton and all is well.

Bottom line… user error confirmed… but fixed :slight_smile:
[import]uid: 6547 topic_id: 10180 reply_id: 37486[/import]