Showing the activity faster

mc73

Well-Known Member
Licensed User
Longtime User
Dear friends,

In VB, I usually bring up a form, with form.show, in order to show it fast, i.e. not wait for all controls to load. In b4a we have the loadLayout, but I was wondering whether there is a tip to show the activity faster, cause in some of my forms, there is a 1.5-2 seconds load time, while the previous activity is still shown. Thank you.
 

mc73

Well-Known Member
Licensed User
Longtime User
You can break the layout file into several layouts and then start with the first piece and load the others later.
All my layouts are made with the designer. I think you mean doing it programmatically?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I understand the logic behind this idea, after all I use it quite often in some of my windows-based apps. The problem is that in b4a I used the designer, this is why I'm asking if there is something that can be done to 'cheat' a little with the android's os while loading the layout :)
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Making 2+ designer layouts splitting the screen like this would be the only thing I can think of. Could also try a doevents at the beginning of create...might make it just show a blank screen faster then you could loadlayout either your whole screen or loadlayout multiple times for your parts of the screen.

Microsoft does this same type of thing in Desktop and WinMobile apps. They usually make the main exe a few kilobytes and it spawns off multiple dll files. I can click 10 different apps on my Windows PC, wait 5 secs and click Outlook last and it will usually still be the first one (or at least 3rd-5th) open. Could try loading pieces of it in threads, but lots of people frown on that lately...something about different contexts and such in other OS although it may be fine in Android.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You could display a splash screen at the start of your app. While the splash screen is displayed, in code, create a panel for each layout file you have. Make all your panels Visible properties = False. Now load all your layouts to their panels. When this is done, remove the splash screen and show the first layout by calling your first Panel.Visible = True.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You could display a splash screen at the start of your app. While the splash screen is displayed, in code, create a panel for each layout file you have. Make all your panels Visible properties = False. Now load all your layouts to their panels. When this is done, remove the splash screen and show the first layout by calling your first Panel.Visible = True.

Dear Margret, your suggestion is great, but I'm using many activities, which are closing and reopening, not just panels in a single activity, in which case your idea would work perfectly.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Making 2+ designer layouts splitting the screen like this would be the only thing I can think of. Could also try a doevents at the beginning of create...might make it just show a blank screen faster then you could loadlayout either your whole screen or loadlayout multiple times for your parts of the screen.

Microsoft does this same type of thing in Desktop and WinMobile apps. They usually make the main exe a few kilobytes and it spawns off multiple dll files. I can click 10 different apps on my Windows PC, wait 5 secs and click Outlook last and it will usually still be the first one (or at least 3rd-5th) open. Could try loading pieces of it in threads, but lots of people frown on that lately...something about different contexts and such in other OS although it may be fine in Android.

Dear Roger,

your suggestion about doEvents makes some progress. Yes, it leaves me with a blank screen in the beginning, but there is an advantage: I don't have to deal with multiclicking of button in the previous activity. I will keep up with doEvents and see if I can proceed with partially loading views, and perhaps in the end I will get the desired result.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Erel, Roger and Margret, thank you all for your ideas, I think that a combination of them, will eventually resolve my 'problem'.:sign0098:
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Yes, I certainly see the issue with multiple Activities. Sorry it didn't help.:eek:

Actually, it DID help! I will also try to load the 3 most used activities while the splash screen, and check whether the environment can support them due to memory issues. Thank you once again, Margret :)
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Where will you store the 3 Activities since they can't be stored as Globals?

Since really Android already sort of caches Activities I wonder if you could store some type of Global Name or Number as to what State the Application is in?

Something like an Integer where:

When it is 0 then the Splash Image Shows then starts Activity 1 which loads and sees the State 0 so visibility sets to False. It could also chain to Activity 2 which sees the State 0 and does the same thing and so on until all the needed activities are cached by Android. The last Activity would then set the global to 1. Using some type of timer or event or something to trigger things it then hides the Splash and Starts Activity 1 which should load quicker...maybe?

Android design just really doesn't allow for much more since every time you switch activities or even rotate the screen it is like it reboots your app. The main advantage and "caching" I imagine is just the Activity itself (Which can be thought of as a class) is loaded into memory already, but the views still need recreated.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I am sorry that I didn't make it clear with my post earlier. When I am passing from one activity to another, I perform an activity.finish. Now, the idea was, that I will not place this exit. Still thinking about it, I haven't get to do this, cause I find good to close activities. Probably I will end up with splitting layouts as already suggested, and see if this method makes things better. At least, logically it will :) Thank you!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
OK, so far, no progress. To demonstrate better my problem with latency (about 1 second, but I didn't get to time it), I've made a small project. There you can see just two activities, one calling the other. The second activity is the 'heavy' one, with some controls. Actually it's just a small part of the controls I use, but all others I've moved to another two layouts, to have them loaded afterwards.
Surprisingly (at least for me) the delay in loading is still there!!! I, on purpose, didn't set any code, just to make sure that the delay is not caused by coding. Any idea would be appreciated.
 

Attachments

  • justatest.zip
    9.2 KB · Views: 223
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Now I've done another thing. I've recreated this test program, in which I can load the layout as usual, or I can manually insert the views. You can find it attached here.
I see difference in loading speed. Is it perhaps my testing device? Any ideas?
 

Attachments

  • justatest_new.zip
    9.3 KB · Views: 246
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
In the device I tested it the manual layout was created in 150ms and the layout file was loaded in 340ms. The file has some overhead. In most cases this overhead is not significant. In other cases, breaking the layout file into several layouts can help.
Erel, to me, 300ms up to 1sec, doesn't really mean something, it's just that some clients have nothing else to complain about :)
Back to the point, I've taken a look at the *bal files, unfortunately jEdit didn't open them properly. Isn't it possible to perform some sort of 'clean up' in such cases?

By the way, I don't have the same latencies on similar devices. For e.g. on a samsung 5.0, I have almost identical times as the ones you've just reported. Then, on a 3.6 and a 4.2, I have bigger difference.
 
Last edited:
Upvote 0
Top