Passing Data From One Page To Another With Storyboard Using Corona

Introduction :
Its a very common practice, where we need to pass data from one page to another page. Corona provides storyboard API, which gives access to page navigation functionality, along with it can also pass data variable with in pages.

Description :
Lets make a scenario where we have home page and menu page and we will pass data from home page to menu page.

CODE BLOCK :

home.lua
 
-- Define options required to page navigation
local options = {
effect = "slideLeft",
time = 400,
params = { name = "Raju" }
}
     
-- Redirect to Menu page
storyboard.gotoScene( "Menu", options )

Lets we have button on home page and onclick of this button we will called the above code block to redirect in menu page.
There I have defined a table variable called ‘options’, which hold the required information for page transition along with our custom variable ‘name’ that I will send to menu page.

menu.lua
 
-- Called when the menu screen's view does not exist and it will create the screen
function menuScreen:createScene( event )
 
-- Define menu screen view
local menuScreenGroup = self.view
 
local homeSceneData = event.params
print( "Welcome "..homeSceneData.name )
 
end

Now in above code block for menu page I have defined a variable that holds home scene data, that we have passed from that page and then I got that value and print that to the console as ‘homeSceneData.name’

Summary :
So,now you know how to pass data from one page to another with storyboard. On similar way we can pass multiple data variable along with page transition functionality with storyboard API.

Note : Tested in Android device.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!