Android Question General question restarting an B4Xpages App

davemorris

Active Member
Licensed User
Longtime User
Hi, Guys

I have come across a question regarding restarting an App – in B4Xpages – which relates in both B4a and B4i.

In my App there is a settings page which allows the user to select what controls are shown on each page. In most cases these pages are setup during their “pagename_Create()” event (which maybe my first mistake).

This works great, until the user decides to change the settings. If these settings change UI pages then problems occur when the pages are re displayed. It this was Windows, I would resort to “Major changes - the Program needs to restart” tactic and simply close the program and restart it automatically.

Unless I have misunderstood something, it is not considered good practice to shut down an App in Android or iOS (not even sure it can be done in B4i) and restart it (there are some old posts which do show how to do it).

As I see it, the pages need to be somehow destroyed so when re-shown the pagename_Created() event runs.

Maybe I am missing something, but it looks to me that I must move most of the code in the _Create() to the _Appear() event to ensure that the page displays the correct views. As you can appreciate this does increase the overheads every time a page is displayed.

Any suggestions or input?

Kind regards

Dave
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Maybe I am missing something, but it looks to me that I must move most of the code in the _Create() to the _Appear() event to ensure that the page displays the correct views.
Create a public Sub whose function is to build the graphical interface of the B4XPage.
You will call it both from the Create event routine (then once only), and from the settings page, when needed.


Or create a public boolean variable (LookChanged?) and use it in the B4XPage_Appear sub-event:
Code:
If LookChanged Then
    'build the GUI here
    '
    '
    LookChanged = False
End If

You will set that variable to True when the user changes the settings and also in B4XPage_Created
 
Last edited:
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
Try something like this:

B4X:
Private Sub Restart
    MyPage.Root.RemoveAllViews
    MyPage.LoadPage
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    
    LoadPage
End Sub

Sub LoadPage
'...'
End Sub
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi, Guys
Thanks for the input – it’s nice to see nobody's suggested a simple method which is already part of B4Xpages that I may have missed.

Just to add to the mix, I found a post from 2020 which makes some suggestions.


It is interesting to note that this post related to seeing an old image when a page is re displayed (another problem I often come against).

I think B4Xpage needs a built-in Reset method for 1 page and say a ResetAllPages if you restarting the App. Sometimes not destroying pages can work against you.

Dave
 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi
What is that magical method?
As above I think a Reset() method is required - however, not sure it is possible as I am not familiar with the inner workings of B4xpages.

Much more often the opposite is true, destroying an Activity can create problems.
Good point, however I don't believe a Reset() method should be like destroying an Activity. Parhaps, I should rephrase it to a "UI Page reset" Method.

Its a bit like the goto() function in "C". In 40 years of programming in "C" I have never used it! But its nice to know its there if required.


Dave
 
Upvote 0
Top