Android Question Splash while initializing pages

angel_

Well-Known Member
Licensed User
Longtime User
I have this code like the example.


B4XMainPage:
Public Sub Initialize
    LoadData
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
   
    Wait For (ShowSplashScreen) Complete (Unused As Boolean)

    LoadLayout
End Sub

Private Sub LoadLayout
    Root.LoadLayout("MainPage")
    '... code'
    InitializePages
End Sub

Private Sub InitializePages
     Settings.Initialize
    B4XPages.AddPageAndCreate("Settings", Settings)
    '...many pages over 20'
End Sub

Sub ShowSplashScreen As ResumableSub
#if B4i
    Main.NavControl.NavigationBarVisible = False
    Root.LoadLayout("Splash")
    ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, "logo.png", ImageView1.Width, ImageView1.Height, True))
    Sleep(3000)
    Root.RemoveAllViews
    Main.NavControl.NavigationBarVisible = True
 #else if B4A
    Dim start As Long = DateTime.Now
    Do While Activity2.HeightChangedFired = False And DateTime.Now < start + 5000
        Sleep(150)
    Loop
    Root.Height = Activity2.CorrectHeight
#End If
    Return True
End Sub

After loading the splash when you initialize pages the screen is black until the process finishes
- Is this behavior normal?
- Can I show the splash while loading all the pages and at the end to close the splash?
- What is the best behavior for the user?
 
Last edited:

angel_

Well-Known Member
Licensed User
Longtime User
The problem is that loading the pages triggers many events such as TextChanged, etc. and this slows down the loading of the pages a lot, is it possible to "freeze" the events of the view until the full load of the pages is completed?
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
These are the times it takes to AddPageAndCreate each page (Release mode):
B4X:
*** a00_page: B4XPage_Created [mainpage]
0.707 s
*** a01_page: B4XPage_Created [mainpage]
0.206 s
*** a02_page: B4XPage_Created [mainpage]
0.502 s
*** a03_page: B4XPage_Created [mainpage]
0.542 s
*** a04_page: B4XPage_Created [mainpage]
0.631 s
*** a05_page: B4XPage_Created [mainpage]
0.204 s
*** a06_page: B4XPage_Created [mainpage]
0.391 s
*** a07_page: B4XPage_Created [mainpage]
0.289 s
*** a08_page: B4XPage_Created [mainpage]
0.398 s
*** a09_page: B4XPage_Created [mainpage]
0.573 s
*** a10_page: B4XPage_Created [mainpage]
0.161 s
*** a11_page: B4XPage_Created [mainpage]
0.058 s
*** a12_page: B4XPage_Created [mainpage]
2.525 s
*** a13_page: B4XPage_Created [mainpage]
0.359 s
*** a14_page: B4XPage_Created [mainpage]
0.35 s
*** a15_page: B4XPage_Created [mainpage]
0.001 s
Almost 8 seconds, Is it too long, do I have to look for another option?
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
I partially solved the problem, the first was that Animation duration = 400, I set it to 0, and the second that the sleep (50) was too short and I put it 500, now after showing the Splash it shows the interface it initializes the pages, but MainPage remains frozen until all the pages are initialized.

Is it possible to initialize the pages while the splash is showing and after initializing them close the splash and show the interface, or is there a way to prevent the app from freezing?

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    
    Wait For (ShowSplashScreen) Complete (Unused As Boolean)

    LoadLayout
    
    Sleep(500)
    InitializePages
End Sub
 
Upvote 0
Top