Hi,
I have the similar issue with multiple times when i back from another scene.
for example:
view1.lua
----------------------------------------------------------------------------------------- -- -- view1.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) local function gotoOknoScene( self, event ) --composer.removeScene( "view") composer.gotoScene("okno") print("goto okno") return true end function scene:create( event ) local sceneGroup = self.view -- Called when the scene's view does not exist. -- -- INSERT code here to initialize the scene -- e.g. add display objects to 'sceneGroup', add touch listeners, etc. -- create a white background to fill screen local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) bg.anchorX = 0 bg.anchorY = 0 bg:setFillColor( 1 ) -- white -- create some text local title = display.newText( "First View", 0, 0, native.systemFont, 32 ) title:setFillColor( 0 ) -- black title.x = display.contentWidth \* 0.5 title.y = 125 local newTextParams = { text = "Loaded by the first tab's\n\"onPress\" listener\nspecified in the 'tabButtons' table", x = 0, y = 0, width = 310, height = 310, font = native.systemFont, fontSize = 14, align = "center" } local summary = display.newText( newTextParams ) summary:setFillColor( 0 ) -- black summary.x = display.contentWidth \* 0.5 + 10 summary.y = title.y + 215 local function CzatFunction(event) gotoOknoScene(); end local czatButton = widget.newButton { left = 10, width=30, top = 255, label = "Test", onEvent = CzatFunction } -- all objects must be added to group (e.g. self.view) sceneGroup:insert( bg ) sceneGroup:insert( title ) sceneGroup:insert( summary ) sceneGroup:insert(czatButton) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then print("view1 SHOW "..phase) -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then -- Called when the scene is on screen and is about to move off screen -- -- INSERT code here to pause the scene -- e.g. stop timers, stop animation, unload sounds, etc.) elseif phase == "did" then print("view1 HIDE "..phase) -- Called when the scene is now off screen end end function scene:destroy( event ) local sceneGroup = self.view --print( "destroy" ) -- Called prior to the removal of scene's "view" (sceneGroup) -- -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene
okno.lua
local composer = require( "composer" ) local scene = composer.newScene() local widget = require( "widget" ) --------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE -- unless "composer.removeScene()" is called. --------------------------------------------------------------------------------- -- local forward references should go here --------------------------------------------------------------------------------- local function gotoViewScene( self, event ) composer.gotoScene("view") return true end -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. local function CzatFunction(event) gotoViewScene(); end local czatButton = widget.newButton { left = 10, width=30, top = 255, label = "Back", onEvent = CzatFunction } sceneGroup:insert( czatButton) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase --print("") if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then print("okno SHOW "..phase) -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then print("okno HIDE "..phase) -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
And after back to view1.lua i’ve got
Apr 23 10:05:50.889: goto okno
Apr 23 10:05:50.896: okno SHOW did
Apr 23 10:05:50.896: view1 HIDE did
Apr 23 10:05:51.018: goto okno
Apr 23 10:05:51.028: okno HIDE did
Apr 23 10:05:51.126: okno SHOW did
Apr 23 10:05:57.067: view1 SHOW did
Apr 23 10:05:57.067: okno HIDE did
Apr 23 10:05:57.198: view1 HIDE did
Apr 23 10:05:57.298: view1 SHOW did
why show,hide and again show?
Attache file with example.
Best Regards,
Piotr