Android Question Open B4XPage with the required parameter.

Sergey_New

Well-Known Member
Licensed User
Longtime User
I use a common function to open Activity2 from Activity1 with the required parameter.
Activity1
B4X:
function.openData("Activity2"),"setData", key)
'    for other pages, the "setData" procedure will be different
function
B4X:
Sub openData(CallBack As Object, fn As String, key As String)
    CallSubDelayed2 (CallBack, fn, key)
End Sub
Activity2
B4X:
Sub setData(key)
'    ...
End Sub
What is the correct way to do this in B4XPages for Page1 and Page2?
My version:
Page1
B4X:
function.openData("Page2","setData", key, False)
function
B4X:
Sub openData(IdPage As String, fn As String, key As String)
    B4XPages.ShowPage(IdPage)
    CallSubDelayed2 (B4XPages.GetPage(IdPage), fn, key)
End Sub
It is right?
 

Rubsanpe

Active Member
Licensed User
Hi. There may be other options but you can directly call the function of the B4XPage through the page created in B4XPages.MainPage

B4X:
B4XPages.MainPage.<variable page definition>.setData(key)

Rubén
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Erel, I don't understand. I need to use the openData procedure located in the function module.
What code is needed in Page1, Page2 and function module?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
In B4XPages the (1) Initialization, (2) Registration (Add or AddPageAndCreate) is usually done in B4XMainPage.

When you want to show a page, it can be anywhere in your app.
Creating a page is only done once, usually by loading some layout and running some setup code.
If Show is called and the page has not yet been created it will do it before displaying the page - BUT only the first time.
Creation is a one-time event.

Show triggers "Sub B4XPage_Appear". It has no parameters (By design, since the parameter signature could vary from page to page.)

If the page needs to be modified before being shown it should be done in "Sub B4XPage_Appear".
If you want to pass parameters when showing a page, first set the values of Public variables in that page.
This includes names of page specific functions that you can invoke with CallSub and CallSubDelayed.
 
Last edited:
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
William Lancee, I read this.
In the example from post #7, I ask you to change the opening of Page2 from Page3.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Andrew (Digitwell) is what I wanted. Thanks a lot!
 
Upvote 0
Top