Android Question Speeding up LoadLayout

Alessandro71

Well-Known Member
Licensed User
Longtime User
My application has a complex layout, with nearly 300 elements (mainly panels and labels).
LoadLayout run time is about 1.6 seconds, during which, an empty activity is shown.
Are there any tips to speed up LoadLayout?
 

sorex

Expert
Licensed User
Longtime User
maybe loading only the items when it is first needed?

just load the menu first then load the rest when the menu is shown or when a button is clicked.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
It’s a single activity app, with several panels that get displayed on demand, but they are all inside the main layout file
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
is there a way to check if a layout has already been loaded?
example:
let's suppose a kind of popup panel
the first time it's displayed, i should call LoadLayout before turning Visible to True
subsequent calls can skip the LoadLayout call and display the panel directly
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just use a boolean variable then you can use

B4X:
if mainMenuLoaded=false then
mainMenu.loadLayout("mainmenu") 'load your layout (not sure if this is the right syntax as I generate by code)
mainMenuLoaded=true
end if
mainMenu.visible=true 'unhide if it was hidden by some menu selection

maybe you can tell without the variable by checking if the panel has childs.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Just an update for all who helped me on this.
I actually split up the big layout file in several smaller ones: one file for each panel.
Before showing a panel I check if the layout for it is already loaded, calling LoadLayout otherwise.
This sped up the initial startup of the app, spreading loading times over the whole lifecycle of the app.
Not all panels are always needed, and those who get loaded on demand, have very little delay, with no user impact.
 
Upvote 0
Top