Android Question [B4XPages] Open a page invisibly or transparently.

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I need to open a page but without views, or that it is transparent, or that it is invisible, that is, that it is not seen that that page has been opened.
I have tried root.visible = False but the screen is white and you can't see what's underneath (the mainpage)
Is it mandatory to use a layout?
It has a solution?
Thank you.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hello, that page performs a series of processes and checks. I used to have views to report results, but I decided to remove them because I no longer need them. Now the page doesn't have any views, but I do need it to keep going through all the processes.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Before, with the "Activity", I made it transparent by putting something like this in the manifest:
SetActivityAttribute(Fpuente, android:theme, @android:style/Theme.Translucent.NoTitleBar)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hello, that page performs a series of processes and checks. I used to have views to report results, but I decided to remove them because I no longer need them. Now the page doesn't have any views, but I do need it to keep going through all the processes.
You can create the page with B4XPages.AddPageAndCreate and access its methods.
A B4XPages class has nothing special, it is a normal class. You are not forced to visualize it using the method B4XPages.ShowPage.

Create it, declare it (I do it always in the Class_Globals of B4XMainPage, as Public object), initialize it and, as Erel wrote, add it to the B4XPages using B4XPages.AddPageAndCreate.

Once done, you can use its methods and properties from everywhere (from another B4XPage, another class, code module, service module).

Example:
B4X:
' Create this B4XPage class; name: clspagMyNeverDisplayedPage

' ... Class_Globals
'... Initialize
'
Public Sub Sum(Add1 As Int, Add2 As Int) As Long
    Return Add1 + Add2
End Sub

B4X:
' B4XMainPage
Sub Class_Globals
    Public NeverDisplayedPage As clspagMyNeverDisplayedPage
'...
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    '... root...
    NeverDisplayedPage.Initialize
    B4XPages.AddPageAndCreate("NeverDisplayedPage", NeverDisplayedPage)
End Sub

B4X:
' From now you can access all methods and properties of your "never displayed page class". From B4XMainPage:
Log(NeverDisplayedPage.Sum(1, 2))

' From other pages / code modules / services / classes:
Log(B4XPages.MainPage.NeverDisplayedPage.Sum(1, 2))

Simply do not show it, do not call B4XPages.ShowPage("NeverDisplayedPage") if you don't want to show it.

You can declare its views as Public and access them:
B4X:
B4XPages.MainPage.NeverDisplayedPage.lblOne.Text = "WOW"  ' very useless, of course.
 

Attachments

  • NeverDisplayedPage.zip
    15.8 KB · Views: 193
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
A B4XPages class has nothing special, it is a normal class. You are not forced to visualize it using the method B4XPages.ShowPage.

Create it, declare it (I do it always in the Class_Globals of B4XMainPage, as Public object), initialize it and, as Erel wrote, add it to the B4XPages using B4XPages.AddPageAndCreate.

Once done, you can use its methods and properties from everywhere (from another B4XPage, another class, code module, service module).
Very accurate answer 👍
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, today I was finally able to test it.
It works perfectly.
I think I am understanding how the "Pages" work.
Thank you.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Simply do not show it, do not call B4XPages.ShowPage("NeverDisplayedPage") if you don't want to show it.
Excellent example @LucaMs . You have become a powerhouse and a B4XPages guru, extremely reliable.
Just a side question: Is it your preference to initialize that 2nd page in the B4XPage_Created of B4XMainPage as opposed to here:
B4X:
Public Sub Initialize
    NeverDisplayedPage.Initialize 'init works here or in B4Xpage_Created
End Sub
I suppose, it does not make a difference, does it.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
And if instead of "public", "private" is used:
Public Private NeverDisplayedPage As clspagMyNeverDisplayedPage
It is that I have put "private" and it works anyway.
It is right?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
And if instead of "public", "private" is used:
Public Private NeverDisplayedPage As clspagMyNeverDisplayedPage
It is that I have put "private" and it works anyway.
It is right?


What if I declare in Process_Globals of B4XMainPage:

Private Button1 As Button
Private KVS As KeyValueStore
Private MP As MediaPlayer

?

Just I cannot "see" - use them outside of B4XMainPage. I will not be able to write:

B4XPages.MainPage.KVS

in my second page, my Starter, my DB code module...
I will able to "see" and use that KVS variable in B4XMainPage only.

The same will be for your NeverDisplayedPage, or any other variable, if declared as Private.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The same will be for your NeverDisplayedPage, or any other variable, if declared as Private.
If you are calling subs in NeverDisplayedPage from B4XPages.MainPage only, you can still declare: the class as private like this:
B4X:
Private NeverDisplayedPage As clspagMyNeverDisplayedPage
It does not have to be Public. But the Subs have to be public. That is the way I understand it, correct?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sure. Private Subs of a class can be called only from inside the class itself.
My question is not about the subs inside the class. My question is about:
Private NeverDisplayedPage As clspagMyNeverDisplayedPage
instead of:
Public NeverDisplayedPage As clspagMyNeverDisplayedPage
 
Upvote 0
Top