Web popup showAlert in listener

If you put a native.showAlert in the listener function for the urlRequest event callback, you’ll see the alert twice, then the app will crash. I’ve tried this with both simulator and on device.

The basic code I’m using is:

[lua]local allowedToAlert = false

local function listener( event )
if (allowedToAlert) then
native.showAlert( “Corona” , “ArticleGetFeed”, { “OK” } )
end

return true
end

local options = { hasBackground=true, baseUrl=system.ResourceDirectory, urlRequest=listener }
native.showWebPopup( “index.html”, options ) – local file

timer.performWithDelay(
1000,
function()
allowedToAlert = true
end,
1
)[/lua]

The timer is there to stop the initial page load from causing the alert to show.

Am I doing something really dumb?

Matt. [import]uid: 8271 topic_id: 16346 reply_id: 316346[/import]

Well, it looks like you may have run into a bug … here’s the bug report page:

http://developer.anscamobile.com/content/bug-submission [import]uid: 52430 topic_id: 16346 reply_id: 61012[/import]

Well, it’s not pretty and shouldn’t be necessary, but for now I’ve gotten around this by limiting the number of times code executes in the urlRequest event listener:

[lua]local allowedToAlert = false
local currentCall = false

local function listener( event )
if (not currentCall) then
currentCall = true
if (allowedToAlert) then
native.showAlert( “Corona” , “ArticleGetFeed”, { “OK” } )
end
currentCall = false
end

return true
end

local options = { hasBackground=true, baseUrl=system.ResourceDirectory, urlRequest=listener }
native.showWebPopup( “index.html”, options ) – local file

timer.performWithDelay(
1000,
function()
allowedToAlert = true
end,
1
)[/lua] [import]uid: 8271 topic_id: 16346 reply_id: 61090[/import]