Bug? child panel still initialized after nav control page removed

Jack Cole

Active Member
Licensed User
I have an app in which I check to see if a panel is initialized in the page_resize event. If it is, then I resize this child panel of the page's root panel. This is used to determine if the layout should be loaded or if the content just needs to be resized.

When I remove a page from the navcontrol, the child panel still shows as being initialized. Is this a bug?

I have attached an example app.

To reproduce the problem:
1) click Open Page.
2) click Back
3) click Open Page again. Notice that nothing loads because the resize event is seeing the panel as still being initialized.

Here is the code where the problem happens.
B4X:
Private Sub Page2_Resize(Width As Int, Height As Int)
    If ChildPanel.IsInitialized Then
        Log("Child is initialized")
        ChildPanel.Width=Width
        ChildPanel.Height=Height
    Else
        Log("Child is not initialized")
        ChildPanel.Initialize("")
        Page2.RootPanel.AddView(ChildPanel,0,0,Width,Height)
        ChildPanel.LoadLayout("newpage")
    End If
End Sub
 

Attachments

Erel

Administrator
Staff member
Licensed User
When I remove a page from the navcontrol, the child panel still shows as being initialized. Is this a bug?
No. There is no relation between a view being initialized and its parent state.
You can call Page.RootPanel.RemoveAllViews and then check whether the view's parent is initialized (assuming that the relevant view was added to the RootPanel and not to a child panel).
 

Jack Cole

Active Member
Licensed User
I have the same problem even when using Page.RootPanel.RemoveAllViews. It even shows the panel as still being initialized when I remove it from the parent using ChildPanel.RemoveViewFromParent.
 

LucaMs

Expert
Licensed User
Given that what I'm about to write is not about B4i and that I don't have B4i...

This usually happens also with B4A Panels; you can remove a View from a Panel (or from an Activity) and assign it to another Panel. The view remains initialized and with all its properties set.

This is a convenience rather than a bug; certainly we should know how to remove them permanently, so as not to waste memory.
 

LucaMs

Expert
Licensed User
After writing my previous post (almost certainly out of place), I realized that this can be a problem (again a memory problem "only") in CustomListViews.

But the problem will be solved by Erel, as I think these my two posts will be removed :) (perhaps rightly)
 

Erel

Administrator
Staff member
Licensed User
I guess maybe you mean I'd have to check the following:

ChildPanel.Parent.IsInitialized
True.

I have the same problem even when using Page.RootPanel.RemoveAllViews
That's expected. As I wrote, there is no relation between a view being initialized and its parent state.
 
Top