Android Question How do you guys get your data passed around between pages?

lonnieh

Member
Licensed User
Longtime User
Hello guys
I am sure this is super simple, but I just can't get my head wrapped around it. For example, I have 2 B4XPages. Page 1 has a database entry with multiple fields, Page 2 is a field editing page that shows when you click on a field in page 1. When I change the field data in page 2, I can choose to save it. If I save it, this is what I am struggling with.

Would you guys just pass Page 1 to Page 2 then create a Page1.Update function and call it from Page 2?

I'm watching tutorials but none of the pages are interacting with each other bidirectionally, I could have missed it.
 

Sandman

Expert
Licensed User
Longtime User
Well, there are several ways of doing what you want. A (very) simplified explanation of what I do is I have a class that contains the data for the app, and that all pages have a reference to that class. Meaning it's the common ground for data-sharing, and all pages can access and manipulate the data in that class. It doesn't have to be more difficult than that.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Hello guys
I am sure this is super simple, but I just can't get my head wrapped around it. For example, I have 2 B4XPages. Page 1 has a database entry with multiple fields, Page 2 is a field editing page that shows when you click on a field in page 1. When I change the field data in page 2, I can choose to save it. If I save it, this is what I am struggling with.

Would you guys just pass Page 1 to Page 2 then create a Page1.Update function and call it from Page 2?

I'm watching tutorials but none of the pages are interacting with each other bidirectionally, I could have missed it.
The way I do this (not saying it is the right way or the best way) is like this:

B4XMainPage has references to all possible B4XPages. This is done in a Sub in B4XMainPage:

B4X:
Sub CreatePage(iPage As Int) As ResumableSub
    
    If mapB4XPages.ContainsKey(iPage) Then
        Return False 'meaning no page created as it was created already
    End If
    
    Select Case iPage
        
        'Menu group 0
        '------------
        Case Enums.eB4XPages.iFindPatients
            cFindPats.Initialize(iPage)
            B4XPages.AddPageAndCreate(Enums.arrB4XPagesNames(iPage), cFindPats)
        Case Enums.eB4XPages.iSinglePatient
            cSinglePat.Initialize(iPage)
            B4XPages.AddPageAndCreate(Enums.arrB4XPagesNames(iPage), cSinglePat)
'ETC.

    End Select
    
    mapB4XPages.Put(iPage, 0)
    
    Return True
    
End Sub

Then all the B4XPages have a reference to B4XMainPage when they are created:

B4X:
Sub Class_Globals

    Private cMP As B4XMainPage

End Sub

Public Sub Initialize(iPageCode As Int) As Object
    
    cMP = B4XPages.GetPage("mainpage")

End Sub
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Pressed a wrong button, so this post went off before it was ready.
Needed to add this:

Then to access code in other pages this is done via a reference to B4XMainPage, so for example:

B4X:
        Case Enums.eB4XPages.iSinglePatient
            Return cMP.cSinglePat.GetOverflowButton(iIndex)

Working all fine for me.

RBS
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Pressed a wrong button, so this post went off before it was ready.
Needed to add this:

Then to access code in other pages this is done via a reference to B4XMainPage, so for example:

B4X:
        Case Enums.eB4XPages.iSinglePatient
            Return cMP.cSinglePat.GetOverflowButton(iIndex)

Working all fine for me.

RBS
1767443926371.png

:)
 
Upvote 0
Top