Android Question [B4X] B4XPages - destroy page to trigger B4XPage_Created again

Alexander Stolte

Expert
Licensed User
Longtime User
Hey,

i have a display problem, i take a image from the camera, then i open a new page to load the image to edit it.
If I would now load the image in the "appear" sub, you will see the old image, until the new one is loaded and all the settings on the page are still there because the page was not destroyed. Another problem is when I load the image in the "appear" sub, if the user briefly leaves the app and comes back, then the image would be loaded again.

So how i can destroy the page?

Thanks
 

Alexander Stolte

Expert
Licensed User
Longtime User
Why aren't you setting the image from the camera page directly? Set it before you show the next page.
Because the page was not loaded before, I know with "AddPageAndCreate" I can load the page directly, but if the user doesn't take a new image, then I don't need the page, so this would be an unnecessary operation or page that is loaded and not needed.
Maybe a "CreatePage" function would help, so I could preload the next page if it has not yet been created, load the image before displaying the page.

Pages are not destroyed. If you want to reset the UI then create a Reset sub in the page and configure the UI as needed.
But then you would also have to make sure that the custom views can be reset. So I would have to add the "Reset" function to my "AS Draw" to reset the painted and the image.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Because the page was not loaded before, I know with "AddPageAndCreate" I can load the page directly, but if the user doesn't take a new image, then I don't need the page
This is a preoptimization thinking. Creating a panel with a few views will take less than a few milliseconds. Nothing to be bothered about.

But then you would also have to make sure that the custom views can be reset. So I would have to add the "Reset" function to my "AS Draw" to reset the painted and the image.
As I said, you have two options:
1. Reset the layout.
2. Remove the layout and load it again.

Both are simple and don't require dealing with the class instance state being lost.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
2. Remove the layout and load it again.
I have decided to go for the second option.

But it needs some config.
B4X:
Sub Class_Globals
Private justinbackground As Boolean = False
Private pageclosed As Boolean = True
End Sub

Private Sub B4XPage_Appear
pageclosed = True
    If justinbackground = False Then
    'LoadLayout
    End If
End Sub

Private Sub B4XPage_Background
    pageclosed = False
    justinbackground = True
End Sub

Private Sub B4XPage_Disappear
    Sleep(0)
    If pageclosed = True Then
        justinbackground = False
        Root.RemoveAllViews
    End If
End Sub
The code prevents the layout from being reset if the user moves the app to the background and then continues the process.
If the user goes back, the layout is reset.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
In my case, I have these codes to handle this situation
B4X:
Sub B4XPage_Appear
    Root.RemoveAllViews
    Root.LoadLayout("mylay")
    'others codes from B4XPage_Created move to this sub
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…