B4J Question B4XPages Splash Screen with background MainForm loading

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
I would like to ask if it's possible to have a startup splash screen and loading/initializing in the background the MainForm, so it's ready to show it!
I have seen Erel's example but I haven't found a way to load the MainForm displaying the splash concurrently and hiding the MainForm.
 

LucaMs

Expert
Licensed User
Longtime User
I'm not sure I understand the question.

In B4XPages projects it is always better not to add code to the Main (which is a Form in B4J, an Activity in B4A and I think, not having it, a Page in B4i).

I think you could use the B4XMainPage as a splash screen and load the second page, which would become the main page of your project, with:

B4XPages.AddPageAndCreate("YourSecondPageID", YourSecondPage)

in the Create event of the B4XMainPage.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
My try is so:

Main:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Resizable = False
    MainForm.SetFormStyle("TRANSPARENT")
    MainForm.Show
 
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
End Sub

B4XMainPage:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
 
    Dim Page1 As FirstPage
    Dim timSplash As Timer
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    CSSUtils.SetBackgroundImage(B4XPages.GetNativeParent(Me).RootPane, File.DirAssets, "B4R_512_512_transparent.png")
    'B4XPages.GetNativeParent(Me).RootPane.Alpha = 0
    'B4XPages.GetNativeParent(Me).RootPane.SetAlphaAnimated(2000, 1)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub B4XPage_Appear
    timSplash.Initialize("timSplash", 500)
    timSplash.Enabled = True
End Sub

Sub timSplash_Tick
    timSplash.Enabled = False
    Page1.Initialize
    B4XPages.AddPageAndCreate("Page1", Page1)
    B4XPages.ShowPageAndRemovePreviousPages("Page1")
End Sub

FirstPage:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    'loading data
    For i = 0 To 1000000
        Log(Rnd(i, i+100))
    Next
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("2")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
 

Attachments

  • b4xSplash2.zip
    19.1 KB · Views: 135
Last edited:
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Hello Luca!
Thank you for your code!
With a few changes worked like a charm!
I had forgotten that I can use the B4XMainPage as starter form!!! ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…