Multiple layouts in B4A

Evadman

Member
Licensed User
Longtime User
I am going to ask what is probably a stupid question that is addressed somewhere, but I can't find it in the documentation because my search-fu is lacking.

I have an extremely complicated app with a bazillion screens. I'm calling them screens because that's what they are from the user's point of view, but I am using layouts in B4A. Basically, the user is pressing a button or otherwise telling the app they want to go to a different screen. To perform that navigation, I am removing the current layout, and adding a new layout. I want to make sure that is the correct/best way to do that function.

The reason I think I am doing this wrong is that the save state lib fails to bring the app back to where it was (brings the app back to a black screen with no loaded layouts). I'm not concerned with the save state lib not working for me, it was just an indicator that I could be doing something wrong with the layout switching.

By the way, I should probably say everything is working (besides save state) with loading layouts like this and the application is lightning quick on the older than dirt phones we are testing with. I am just getting annoyed with the huge amount of code that I have in one place, the activity module.

Here is an example flow and some quick psudocode with user actions in braces:
B4X:
{Application opened}
    loadlayout "Home"
{User presses "open order page" button}
    closealllayouts()
    getdatafororderpage()
    loadlayout "Order Page"
{User presses "detail on item" button}
    closealllayouts()
    getdataforitempage()
    loadlayout "item detail"
{User presses "done" button}
    closealllayouts()
    loadlayout "home"

Is this the best way to perform this type of navigation in B4A? Thanks!
 
Last edited:

GaNdAlF89

Active Member
Licensed User
Longtime User
You can navigate to activities with "StartActivity(ActivityName)" pressing a button to start a new activity, and "Activity.LoadLayout(LayoutName)" in his Sub Activity_Create to load layout; use "Activity.Finish" to close it.
Sorry for my english!
 
Upvote 0
Top