Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Navigation A=>B=>C
Started by leojharris Jul 14 2018 08:18 PM

- - - - -
6 replies to this topic
navigation
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

leojharris

[GLOBAL: userInfoPane.html]
leojharris
  • Observer

  • 18 posts
  • Corona SDK

Hi all,

 

Question: regarding page navigation if I have scene A => B => C. If I want to get to scene C I go through B such that composer.gotoScene(B) and in B I call composer.gotoScene©. The problem I am having is going back to B. If I call composer.removeScene© and then composer.gotoScene(B) I get a blankscreen. If I call composer.gotoScene(B) I also get a blank screen, but if I call composer.removeScene© this takes me back to the scene A. How can I simply go back to scene B from C



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,328 posts
  • Corona Staff

Can you share some code?

 

Rob



[TOPIC: post.html]
#3

leojharris

[GLOBAL: userInfoPane.html]
leojharris
  • Observer

  • 18 posts
  • Corona SDK

Sure:

 

I have a menu page (scene A) I am calling: 

 

onRelease = function()
composer.gotoScene('scenes.leader_board_menu')
end
})

 

Then in my leader_board_menu (Scene B )I call:

 

onRelease = function()
composer.gotoScene('scenes.leader_board_distance')
end
})
 
Then in the leader_board_distance (scene C ) I call:
 
local function onKeyEvent( event )
  -- If the "back" key was pressed on Android or Windows Phone, make sure it gets back to menu
  if ( event.keyName == "back" ) then
    local platformName = system.getInfo( "platformName" )
    if ( platformName == "Android" ) or ( platformName == "WinPhone" ) then
composer.removeScene("scenes.leader_board_distance")
    end
  end
  return true
end
Runtime:addEventListener( "key", onKeyEvent )
 
Unfortunately it keeps taking me back to the menu page, but I just wanted it to go back to leader_board_menu (Scene B).
 
If you need to see more code let me know but regarding navigation this is all I am doing


[TOPIC: post.html]
#4

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 235 posts
  • Corona SDK

Please if you are on a computer use the <> to paste your code.

I try the same your are trying to do beacause I think if i use a runtime listener across all scenes it's worse than using it in every scene adding and removing the runtime listener. But the best way to achieve the Android back key is to use a function in your main lua setting a composer variable to trace your app flow.

I would like to ask the moderators why the "Androidizing your Corona app tutorial" disapperar from the whole galaxy?

I don't have the time right now to explain the whole thing but if you read the docs trying to understand how you can get composer stage it would be very helpful, then try to create a variable that composer can read from your main lua to every scene.

You need to understand event.keyName and event.phase from the key events and use the composer.getSceneName() api.
What I could never understand is that the programmers here used a variable "lastScene" with a "composer.returnTo" assignment that I have never found in Corona's documents.

Would be very helpful if @Rob or some experienced programmer did a tutorial explaining how to implement the android back button in corona apps.

When I have finished all I have to do to upload my app to the Play Store I will go through here if you still need help.

DoDi

[TOPIC: post.html]
#5

leojharris

[GLOBAL: userInfoPane.html]
leojharris
  • Observer

  • 18 posts
  • Corona SDK

Please if you are on a computer use the <> to paste your code.

 

Have made changes. Thanks



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,328 posts
  • Corona Staff

You should never remove the scene you're in. Your back button should to a composer.gotoScene() not a composer.removeScene().  There is only one place to safely call composer.removeScene() in the scene you're in and that's after you've called composer.gotoScene() and you've received the scene:hide()'s "did" phase event. That event happens after the new scene is fully on the screen and the scene you are leaving is no longer visible.

 

Normally you shouldn't need to remove a scene unless you need to do a complete reset on the scene or unless it takes up a lot of memory. 

 

Rob



[TOPIC: post.html]
#7

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 235 posts
  • Corona SDK

@leojharris

I forgot I have created this topic I think it would be helpful. Here you have a point to start, then when you realize what it's you approach and you feel comfortable you will edit you code for your taste. 




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: navigation