Android Question [SOLVED] [B4X] MainPage FirstTime

makis_best

Active Member
Licensed User
Hello

With the Default method on Activity_Create we can check FirstTime run.
With B4XPages how we can check FirstTime?

Thank you.
 
Last edited:

LucaMs

Expert
Licensed User
Maybe he might need a "first time appeared".
A private variable in the Class_Globals would be sufficient.
B4X:
Sub Class_Globals
    Private mFirstTimeAppeared As Boolean = True


Private Sub B4XPage_Appear
   If mFirstTimeAppeared Then
   Else
   End If

   mFirstTimeAppeared = False
End Sub
 
Last edited:

makis_best

Active Member
Licensed User
@LucaMs I try your idea using B4XPage_Appear and with B4XPage_Disappear but does not work.
keep running the code I want to run for once.
 

LucaMs

Expert
Licensed User
@LucaMs I try your idea using B4XPage_Appear and with B4XPage_Disappear but does not work.
keep running the code I want to run for once.
I hope you haven't changed the value of mFirstTimeAppeared in the B4XPage_Disappear.
It should work.
 

makis_best

Active Member
Licensed User
Correct... I just find it out... My mistake.
Now Working fine.
I mess around B4XPage_Appear and B4XPage_Disappear.

Thank you all.
 

LucaMs

Expert
Licensed User
Why such complicated solution??????
You almost never need to handle the Appear / Disappear events.

Put the code in B4XPage_Created of B4XMainPage class. It runs once. Exactly like Activity_Create (FirstTime = True)
the boss is always right !
Not this time 😊

If you have to, like I have to, show something and work on something that includes resumable calls only once, I can't write this code in the Created routine, then I need "such a "complicated" solution" 😊
 

makis_best

Active Member
Licensed User
Why such complicated solution??????
You almost never need to handle the Appear / Disappear events.

Put the code in B4XPage_Created of B4XMainPage class. It runs once. Exactly like Activity_Create (FirstTime = True)
And how we check FirstTime = False?
B4XPage_Created load only once not every time page show.
 

Erel

Administrator
Staff member
Licensed User
B4XPage_Created load only once not every time page show.
And that is a very good thing.

If you do want to do something when the page appears then use that event.

In my experience, the Appear event, is used in many cases when developers try to imitate the complex activities behavior, and don't realize that you can directly access the page elements and do whatever you need immediately.

The Appear event can be useful to enable timers for example.
 

makis_best

Active Member
Licensed User
Ok... In my case I load a layout first time the page created and I load a second one when I get back to the that page.
How else to do if not control B4XPage_Appear?
 
Top