Android Question Multiple executions of the same loadlayout

chuck3e

Active Member
Licensed User
Longtime User
If my app does multiple executions of the same Loadlayout, do the previous Loadlayouts accumulate in memory? Or is there something I need to do to cleanup older Loadlayouts?
 

DonManfred

Expert
Licensed User
Longtime User
No
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
I'm not sure what you are asking. Existing views will never be removed as a result of calling LoadLayout.
I understand. It is hard to ask accurate questions via text. I think DonManfred has my answer, but to clarify: Depending on how often the user wants to return to the same layout, it may get loaded many times. My concern is if I need to do something to "clean it out" before loading the same one again, or will it keep building up somewhere in memory and causing some resource limit to be exceeded.
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I understand. It is hard to ask accurate questions via text. I think DonManfred has my answer, but to clarify: Depending on how often the user wants to return to the same view, it may get loaded many times. My concern is if I need to do something to "clean it out" before loading the same one again, or will it keep building up somewhere in memory and causing some resource limit to be exceeded.

Do you mean the user goes from your main activity to another activity & then returns to the main activity (& does so multiple times)? AFAIK the main activity stays in memory unless the OS needs to kill it - in which case it will be reloaded when the user returns to it. Either way there is never more than one instance of the activity & its related layout & views.

- Colin.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Do you mean the user goes from your main activity to another activity & then returns to the main activity (& does so multiple times)? AFAIK the main activity stays in memory unless the OS needs to kill it - in which case it will be reloaded when the user returns to it. Either way there is never more than one instance of the activity & its related layout & views.

- Colin.
Computersmith6, thank you for your reply. I used the wrong word "view". I changed the word "view" to "layout" in my previous question.

Put another way: For instance, using only one activity, can I execute a loadlayout 1,000,000 times during the execution of that activity without causing some kind of memory build up that will eventually crash the app, or must I do some kind of "clean up" before the next loadlayout. And the loadlayout has only a short text to read. doesn't do anything else. I don't intend to do that many, but I used 1,000,000 to stress the point. I'm assuming, based on DonManfred's reply, that that's not something to worry about.
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I think @Erel answered that already by saying that existing views are removed as a result of calling LoadLayout - ie: the layout is effectively reset. The question is: why would you want to load the same layout multiple times in an activity? It doesn't sound like something you would normally do, so perhaps there's another way to achieve whatever it is you're trying to achieve?

- Colin.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think @Erel answered that already by saying that existing views are removed as a result of calling LoadLayout - ie: the layout is effectively reset. The question is: why would you want to load the same layout multiple times in an activity? It doesn't sound like something you would normally do, so perhaps there's another way to achieve whatever it is you're trying to achieve?

- Colin.
Calling LoadLayout will load a new layout on top of the existing activity or panel, no? Unless we use RemoveAllViews.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Calling LoadLayout will load a new layout on top of the existing activity or panel, no? Unless we use RemoveAllViews.
Oops - yes. I misread Erel's reply. :) Still begs the question as to why you would want to load the same layout multiple times...

- Colin.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Oops - yes. I misread Erel's reply. :) Still begs the question as to why you would want to load the same layout multiple times...

- Colin.
I have the same practice that I use the same Activity or B4XPage, let say I call it User. I called different “mode” from other starting module to load different layouts such as “Login”, “Register”, “Reset Password” in a single activity or page.

Edit: Sorry, I realize I actually loading different layouts not the same layout. ?
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Erel, DonManfred, aeric and Computersmith6, thank you for your replies. You make this a great forum. I asked this question because it appears that, when I release my app on Google Play, its testing robot pokes my buttons many times during its test, and my concern is I might get flagged for not releasing memory, or something.

But I do know, if I keep pressing the same button over and over, eventually performance begins to slows down. This is telling me that something is accumulating in memory (filling a buffer or something?), and affecting performance.

Perhaps there is another way to achieve my goal, but I like the way the loadlayout swoops into the display. It's pretty cool, and I don't have to add extra logic to make it do that. And the user may want to visit the same button multiple times to re-read the text. Understand though, this isn't a critical issue for a user. They would never push the same button enough times to cause this, but it does look to me that there is something not right.

Also, aeric, thank you very much - you mentioned "RemoveAllViews". I need to research that. On the smaller cellphone displays, I have to load the 2nd layout on top of those buttons and it appears the Google robot can poke them even when they're covered by that 2nd layout. I need to figure that out too. I have tried "view".enabled = false/true to off the buttons in that case, but that created other program flow issues for me.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I have followed this thread a bit.
Sorry, but I still do not understand what exactly you want to do.
The simplest way would be to post a test project showing what you have done and explain in detail what you want to to, at least for me.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Activity and Panel which can contain other views, both can remove it's child views.
While Panel is also a view and other views such as Label can remove itself.
B4X:
Activity.RemoveAllViews  ' remove all it's child views
Activity.RemoveViewAt(0) ' remove it's child view with index 0

panel.RemoveAllViews     ' remove all it's child views
panel.RemoveViewAt(0)    ' remove it's child view with index 0
panel.RemoveView         ' remove itself from it's parent

label.RemoveView         ' remove itself from it's parent
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
klaus, thank you for your reply. I'm satisfied at this point that my concern is trivial enough for me to ignore. It's not really an issue my users will encounter. Only if Google Play takes issue with it, but apparently no one else has seen a problem, and there must be lots of apps created by B4a on Google Play. As I get time, I will create a simple app to attempt to duplicate this and post it here. If even for my own amusement and amazement.
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
Activity and Panel which can contain other views, both can remove it's child views.
While Panel is also a view and other views such as Label can remove itself.
B4X:
Activity.RemoveAllViews  ' remove all it's child views
Activity.RemoveViewAt(0) ' remove it's child view with index 0

panel.RemoveAllViews     ' remove all it's child views
panel.RemoveViewAt(0)    ' remove it's child view with index 0
panel.RemoveView         ' remove itself from it's parent

label.RemoveView         ' remove itself from it's parent

Thanks much, aeric. I'll play around with these to see if they help.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
[...] and there must be lots of apps created by B4a on Google Play. [...]

Yes - but I doubt that many of them (if any) are calling LoadLayout to reload the same layout multiple times. It's just not good practice to reload a layout every time a user presses a button. If you're doing this just because you want some animation as text is loaded into a view, there are probably better ways to do it. Having said that, you haven't adequately described what it is you're doing (or provided the code you're using), so it's impossible to say whether your approach is likely to be problematic.

- Colin.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Yes - but I doubt that many of them (if any) are calling LoadLayout to reload the same layout multiple times.
For me, the answer is simply none of the apps will load several times the same layout, sorry for being crude, it's non sense.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thanks much, aeric. I'll play around with these to see if they help.

The way I do this is like this:
I have Main and a number of layouts, all on a different panel.
Main has a Sub GoPanel(iPanel As Int)
This Sub will show the different panels.
If that panel is not initialized yet (so that means the layout is not loaded yet) then that layout is loaded and that panel is set to visible and all other panels are set to invisible.
If that panel is already initialized then all GoToPanel will do is set that panel visible and set all other panels to invisible.
So, every layout is only loaded once.
Not sure this is the best way but it works fine.
Have used B4XPages yet, but will change to that setup in the near future as it seems to have serious benefits. Not being able to rotate the app to landscape and back
is no problem for me.

RBS
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
For me, the answer is simply none of the apps will load several times the same layout, sorry for being crude, it's non sense.

I want to thank everyone for replying to my questions, and extend that thanks to RB Smissaert's recent reply and coding suggestion. And Klaus, I take no offense. I agree that you and the others with the same comment are absolutely correct.

Before you all think I am a total goofball, I need to tell you that I never intended for a user to do the same load layout multiple times, and I will insert code to make sure that doesn't happen. However, when my app updates release to Google Play, as part of their internal testing process, they are being tested by a robot they use to put an app through its paces. I noticed it pressing the buttons multiple times. I decided to see what would happen if I did that.

I discovered that after pressing the same button about 40 times in a row, causing the same loadlayout to be executed that many times in a row, performance began to slow down noticeably. When it did I could even wait several minutes before pressing again, and performance of the loadlayout was still slowed, so it wasn't my code buffering up causing that. This tells me that the loadlayout is building something up in memory and affecting performance somehow. I thought someone ought to know that, and maybe they already do. As far as I'm concerned, and if no one else is concerned, at this point, this question of mine can be closed out.

Again, thank you everyone. This is the best forum I have ever used.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I want to thank everyone for replying to my questions, and extend that thanks to RB Smissaert's recent reply and coding suggestion. And Klaus, I take no offense. I agree that you and the others with the same comment are absolutely correct.

Before you all think I am a total goofball, I need to tell you that I never intended for a user to do the same load layout multiple times, and I will insert code to make sure that doesn't happen. However, when my app updates release to Google Play, as part of their internal testing process, they are being tested by a robot they use to put an app through its paces. I noticed it pressing the buttons multiple times. I decided to see what would happen if I did that.

I discovered that after pressing the same button about 40 times in a row, causing the same loadlayout to be executed that many times in a row, performance began to slow down noticeably. When it did I could even wait several minutes before pressing again, and performance of the loadlayout was still slowed, so it wasn't my code buffering up causing that. This tells me that the loadlayout is building something up in memory and affecting performance somehow. I thought someone ought to know that, and maybe they already do. As far as I'm concerned, and if no one else is concerned, at this point, this question of mine can be closed out.

Again, thank you everyone. This is the best forum I have ever used.
I think your findings is good and useful to remind us to avoid this kind of thing to happen. I will bear in mind when my apps need to publish to play store.
 
Upvote 0
Top