Android Question [SOLVED] [B4X] MainPage FirstTime

makis_best

Well-Known Member
Licensed User
Longtime 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:

DonManfred

Expert
Licensed User
Longtime User
As B4XPages never gets destroyed FirstTime = false never happen
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime 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:
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

makis_best

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

Thank you all.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime 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" ?
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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.
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime 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?
 
Upvote 0
Top