Android Question Loading layouts - going back to previous

Albert Kallal

Licensed User
Ok, brand new user - just purchased + installed on Friday.

(a very impressive product by the way). Dropped in a few buttons, tested some code! - it all worked.
Then dropped in a progress bar - guessed that sleep() would work and it did. This product does a very nice job of "leveraging" the Android UI.
(really, very amazing so far). A few code snips later, and I have SQLite working on a test database.

Ok, so my question is kind of the "zen" of B4A.

If I have just loaded my main view - (a few buttons with a simple MsgBox("Hello", "My first button!)

Now, if I want a button to launch + load another view (layout), I would likely hide the current view/layout.

Do I (or should I) setup some kind of page?

Can I just launch another layout, hide previous. do my stuff, and then return to previous
(this is the basic "design" approach my brain is wired up with - open to having to change my approach).

I just tested this,


and of course this layout does load, and display. It of course renders on top of the existing layout.

So, can I hide the first "main" layout? (or should I introduce some kind of page object?

I guess the question is somewhat navigation in applications.

I am open to "don't do things" this way.

But, just looking for a quick tip as to how one will click on a button, and jump to the next form/layout in a typical application.

So, do I (or should I) try and set the current layout to Visible = false, launch next layout. And when done to return, hide current, and show previous?

One can argue that this UI means the 2nd form is "modal" in nature - but at this point, the goal is not really model but a simple jump to a form/layout, and then returing to previous

Albert D. Kallal
Edmonton, Alberta, Canada

Albert Kallal

Licensed User
Thank you kindly.

I think I got this. A bit of reading on my part - especially this:

Not yet 100% sure if/how to add a panel and use it.

However, at the most base level, I have this working.

I have:

Sub Globals

    Private Button1 As Button

    Dim pn1 As Panel
    Dim pn2 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.AddView(pn1,0,0,100%x, 100%y)

   pn2.Visible = False
End Sub
Now on a button, I can show the 2nd form, and hide the first:

pn2.Visible = True

And to close back (return to previous), then I can go:

Sub MyEditClose_Click

   pn2.Visible = False
   pn1.Visible = True

End Sub
Now, having this working?

Did I really have to create the first instance (panel) of pn1?

If I just go Activity.LoadLayout("Some Layout"), is this added to some base collection object? (that I can reference?).

I see lots of code - they just tend to execute a Activity.LoadLayout() and NOT create a panel var to hold that layout.

Last but not least?

I well grasp that I should use some kind of "nav panel", or whatever they are called in B4A, and this would thus reduce me the developer to hide/show forms in code, and let more of the UI do this work for me. But, baby steps - baby steps!

So, I guess my next bus stop is to try adding a panel to the designer (and adopt the "zen" of B4A, and not code such things on my own).

So, my only real question is did I have to create the first panel object (pn1) in code, or could have I just executed a Activity.LoadLayout("Form1"), and then later on referenced some built on object? Or if I need to create the first panel object in code, and THEN reference that first LoadLayout as I did.
(ie: is the only way to get a reference to the first layout I loaded is to create a panel var/object in code?

This just comes down to me grasping the B4A objectmodel.

Anyway, again, thank you. (and again - what a amazing product - only a few hours into this, and am rather enjoying this!).

Albert Kallal
Edmonton, Alberta, Canada

Albert Kallal

Licensed User
Don't use Msgbox. Only MsgboxAsync.

Consider using two activities, one for each of the layouts.
Very well! - had noticed both MsgBox and MasgBoxAsync seem to be async anyway.

As for two activities?

Yes, my "brain" light bulb just realized that when using loadlayout, I am in a sense loading that layout into the "servicer" (the activity) for that given layout.

So, thank you kindly - as this answers the perplexing question I had as to where the Activity.loadLayout goes if I don't create a panel var/object and use that method of the panel object to load.

So, Activites.LoadLayout() means exactly what it means!

Now, I suppose I "could" do as I did, and use one activity to load up several layouts, but having a activity for each form (layout) will allow such forms to be managed correctly and separately by the Android event model. (rotate, events, or even Mr. Android deciding to put to sleep or halt the given Activity).

Considering that I am just few hours into this?

I used a lot of dev tools, and a truckload of IDE's and systems.

So far?

Beyond an amazing product - it is exceeding all my expectations.

Again, thank you kindly,

Albert D. Kallal
Edmonton, Alberta, Canada.


Licensed User


Licensed User
Very well! - had noticed both MsgBox and MsgBoxAsync seem to be async anyway.
Even though you seem to be an experienced developer already as a point of information to avoid future confusion :-

Msgbox is modal, though it does pump the app's message queue, it blocks the the Sub it is called in whose code does not continue running until the message box is closed.

MsgBoxAsync is not modal and returns to run the rest of the code in the Sub immediately after displaying the message box so you need to use 'Wait For' if you need to receive and process the user response.

It is well worth getting your head round 'Wait For' and 'Sleep()' though if you have not used the equivalents in other languages it can seem a bit strange at first. Watch the 'Resumable Subs' video in the tutorials link that Klaus posted above and read my (sort of ) explanation in

Albert Kallal

Licensed User
Msgbox is modal, though it does pump the app's message queue,\running until the message box is closed.
MsgBoxAsync is not modal and returns to run the rest of the code
worth getting your head round 'Wait For' and 'Sleep()'
yes I noticed the message que makes it out - but code halts. (like doEvents in VB, or VBA to flush the pending event que).

And this is re-entrant code! - I noticed that just placing a sleep() in the routine, then B4A IDE like magic tips one off with the "resumeable" icon placed beside the routine - very nice touch!

Don't want to clutter up this board with thank you thank you,

- but much thanks to Klaus for that load layout example. It is simple, but shows truckloads as to how one can approach this (thank you). That simple example really is nice.

Great follow ups - thanks a bunch to all here.

Albert D Kallal
Edmonton, Alberta, Canada