Android Question Reduce the time to start the app

angel_

Well-Known Member
Licensed User
Longtime User
I have an app that if I use B4XPages.AddPageAndCreate for each page it takes too long, I have tried to use Splash but the time is still high, I think the problem is that after loading the design I fill in the fields (the event is launched) and in each field I recalculate and there are many fields.

I have something like this:

B4XMainPage:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    LoadLayOut
    FillFields    'with KeyValueStore
    Calculate1
    Calculate2
'code
End Sub

I was planning to do the following to prevent filling in the fields (B4XComboBox, editText, etc.) from performing the calculations, is that correct? Are there better options?

B4X:
Sub Class_Globals
    Private StartWithoutCalculating As Boolean
End Sub

B4XMainPage:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    StartWithoutCalculating = True
    LoadLayOut
    FillFields    'with KeyValueStore
    StartWithoutCalculating = False
    Calculate1
    Calculate2
'code
End Sub

B4X:
Sub Calculate1
    If StartWithoutCalculating Then Return
    'code
End Sub

Sub Calculate2
    If StartWithoutCalculating Then Return
    'code
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private mFirstTime As Boolean
End Sub
   
Private Sub B4XPage_Created (Root1 As B4XView)
    mFirstTime = True
    Root = Root1
    LoadLayOut
    FillFields    'with KeyValueStore
'code
End Sub

Private Sub B4XPage_Appear
    If mFirstTime Then
        Calculate1
        Calculate2
    End If
    mFirstTime = False
End Sub

B4X:
Sub Calculate1
    'code
End Sub

Sub Calculate2
    'code
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
No need to have a "first time" variable.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    LoadLayOut
    Sleep(100)
    FillFields    'with KeyValueStore
'code
End Sub

With that said, I'm pretty sure that you can optimize the actual slow part. If loading the data from KVS takes too long then load it asynchronously with KVS.GetMapAsync.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
No need to have a "first time" variable.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    LoadLayOut
    Sleep(100)
    FillFields    'with KeyValueStore
'code
End Sub

With that said, I'm pretty sure that you can optimize the actual slow part. If loading the data from KVS takes too long then load it asynchronously with KVS.GetMapAsync.
?

That Sleep does not convince me.

When he calls AddPageAndCreate from the MainPage I think the LoadLayout would be executed but after only 100ms the flow would continue with the execution of FillFields, which, among other things, he ruled out as "guilty" of the slowness, he wants the calculation routines not to be executed right away.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private mFirstTime As Boolean
End Sub
 
Private Sub B4XPage_Created (Root1 As B4XView)
    mFirstTime = True
    Root = Root1
    LoadLayOut
    FillFields    'with KeyValueStore
'code
End Sub

Private Sub B4XPage_Appear
    If mFirstTime Then
        Calculate1
        Calculate2
    End If
    mFirstTime = False
End Sub

B4X:
Sub Calculate1
    'code
End Sub

Sub Calculate2
    'code
End Sub
Maybe I have not explained well, the events of the views call the Sub Calculate1, ... so I need to introduce the conditional in within the subs

B4X:
Sub B4XFloatTextField1_TextChanged (Old As String, New As String)
    '....
    Calculate1'
End Sub

Sub B4XFloatTextField2_TextChanged (Old As String, New As String)
    '....
    Calculate2'
End Sub
'....'
 
Last edited:
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
The calculations will not be executed right away. Only after 100ms. This will allow the layout to appear.
The problem is that each event in the view calls a calculate function, it would be possible to cancel these events (B4XComboBox_SelectedIndexChanged, B4XFloatTextField_TextChanged, etc.) that are fired by filling in the fields (with kvs.GetDefault...) until the LoadLayout is finished and then calling all the calculations?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The problem is that each event in the view calls a calculate function, it would be possible to cancel these events (B4XComboBox_SelectedIndexChanged, B4XFloatTextField_TextChanged, etc.) that are fired by filling in the fields (with kvs.GetDefault...) until the LoadLayout is finished and then calling all the calculations?
I need to introduce the conditional in within the subs
You have to do it (in calculation subs or views event subs).
 
Upvote 0
Top