Android Question NavControl from B4I to B4A

mare1980k1

Member
Licensed User
Longtime User
Is there a code similar to

NavControl.ShowPage(Page1)

in B4A?
I just want to go to previous Activity in B4A when i click back button... Any ideas? I don't want to do the "Button.Visible = true/false" anymore..
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Android doesn't support the concept of navigation controllers in the way that iOS does, however...

If you have launched an activity from another activity, then when you tap the back button on the device the current activity will close & you'll be returned to the previous activity. Am I missing something?

- Colin.
 
Upvote 0

mare1980k1

Member
Licensed User
Longtime User
Colin, when i do Activity.LoadLayout ("2") (Main activity is 1) then i get layout of activity 1 and layout of activity 2 at the same time... By layout i mean designer settings... I will try with startactivity :)
Edit: StartActivity works fine. :)
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Colin, when i do Activity.LoadLayout ("2") (Main activity is 1) then i get layout of activity 1 and layout of activity 2 at the same time... By layout i mean designer settings... I will try with startactivity :)
Edit: StartActivity works fine. :)
Yes - I don't think loading multiple layouts in an activity is the most efficient way of navigating through your app. Using separate activities for your different layouts & loading them with StartActivity is definitely the way to go!

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
You could use:

B4X:
     StartActivity("Main") '- to take you back to the Main Activity.

I've never actually tried this, but I imagine it might cause some issues if you have come from the main activity - because I don't think using StartActivity actually unloads the calling activity (so I'm guessing you might end up with 2 instances of your Main activity).

I could be wrong though...

- Colin.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes - I don't think loading multiple layouts in an activity is the most efficient way of navigating through your app. Using separate activities for your different layouts & loading them with StartActivity is definitely the way to go!
I agree.

1. Note that you should use StartActivity(Main) instead of StartActivity("Main")
2. You will not end with two instances. If an activity is already in the activities stack then it will just move to the front.
 
Upvote 0
Top