media.selectphoto not returning in button event

As the title says, when the user presses a button I want to call the media.selectphoto button

local function toSelectPhoto()

       media.selectPhoto( { mediaSource=media.PhotoLibrary, listener=onComplete ,destination = {                    baseDir=system.TemporaryDirectory, filename=imageName, type=“image” } } )

end

local function handleButtonEvent2( evented )

   if media.hasSource( media.PhotoLibrary ) then

      toSelectPhoto()

   else

If i make this same call(toSelectPhoto) on screen load it works fine and returns with the image.  But when I make this call on the button event, after the user has selected a photo it does nothing.  I am guessing it has something to do with the button listener event ending before the selectPhoto listener has saved the file? (Testing on android galaxy note 2) Thanks for the help!

Hi @bbidarian7,

Please show your button construction code too. The community/staff will need full context of your setup to help.

Also, please surround your code in the forums with “lua” tags for clarity:

[lua] -- your code [/lua]

Thanks,

Brent

Hi @bbidarian7,

Please show your button construction code too. The community/staff will need full context of your setup to help.

Also, please surround your code in the forums with “lua” tags for clarity:

[lua] -- your code [/lua]

Thanks,

Brent