Android Question [B4XPages] How to get MainPage Id

Cableguy

Expert
Licensed User
Longtime User
Hi Guys and Gals...

My first page showing is other than MainPage, But at some point, I would like to show MainPage....
The problem lies exactly here : While the close method takes an object as argument, the show method takes a String, and I can't figure out what the ID is.
I have stried strings like "mainpage" ; "MainPage" ; "B4XMainPage" and a few others, but nothing seems to work.

Help!!

Thanks in advance
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Log(B4XPages.GetPageId(Me))   'Log: mainpage
End Sub

However, if you can't get back to "mainpage", you may have removed it with .ShowPageAndRemovePreviousPages(..)
How do you show your first page?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Log(B4XPages.GetPageId(Me))   'Log: mainpage
End Sub

However, if you can't get back to "mainpage", you may have removed it with .ShowPageAndRemovePreviousPages(..)
How do you show your first page?
Thanks, You sent me in the right direction.... I had searched for some sort of getId, but ihad somehow eluded me.
I also found that you need to first call B4XPages.show to show the page you want to show, before closing the current page.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I also found that you need to first call B4XPages.show to show the page you want to show, before closing the current page.

Unless you put it in:
B4X:
Private Sub B4XPage_CloseRequest As ResumableSub
    B4XPages.ShowPage("mainpage")   
    Return True
End Sub
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thanks for the pointer...

In my particular case, I'm thinking of showing a few "secondary" pages before showing MainPage (where all good stuff will happen), so I prefer the "Show before close" logic that allows me to do it all from MainPage instead of managing each page close request
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Also note that you don't need to close a page before showing another.

The pages are in a stack, so that all you need to do is
B4XPages.ShowPage("mainpage")
No need to close the current page.

Ed: changed queue to stack
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Also note that you don't need to close a page before showing another.

The pages are in a queue, so that all you need to do is
B4XPages.ShowPage("mainpage")
No need to close the current page.
I know but I only need this page once throuout the app living cycle.
I'm even considering removing it from the stack once I'm done with it.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
That makes sense.

For completeness, I should correct my post #8, "queues" are First In First Out (FIFO) structures.
B4XPages are in a "stack" which is Last In First Out (LIFO).
 
Upvote 0

GianniGntl

Member
Licensed User
Hi Guys and Gals...

My first page showing is other than MainPage, But at some point, I would like to show MainPage....
The problem lies exactly here : While the close method takes an object as argument, the show method takes a String, and I can't figure out what the ID is.
I have stried strings like "mainpage" ; "MainPage" ; "B4XMainPage" and a few others, but nothing seems to work.

Help!!

Thanks in advance
B4X:
Dim MainPageId As String = B4XPages.GetManager.FindPIFromB4XPage(B4XPages.MainPage).Id
 
Upvote 0
Top