Android Question B4XPages GlobalContext

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
Assuming that we should not use starter service when implementing B4XPages in case we think cross platform, I will use the following Erel's answer to a previous post of mine and I will ask where to declare the GlobalContext (Maybe at MainPage or Main Activity?):

Starter service:
B4X:
Sub Service_Create
Dim AppGlobals As clsGlobals
AppGlobals.Initialize
B4XPages.GlobalContext = AppGlobals
End Sub

Thank you in advance!
 

vfafou

Well-Known Member
Licensed User
Longtime User
B4XMainPage - Sub Initialize.


(Main Activity is not cross-platform, it is B4A only, of course)
Thank you very much Luca! I have already done the change. Including GlobalContext I have moved all my global declarations to MainPage.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I suppose he wants declare and initialize global variables.
No need a class, for this, just create a code module and a "Sub Init" in it (call modGlobals.Init from sub Initialize of B4XMainPage).
This code module might be shared between platforms ("Add module to parent folder") or not (used by B4A only).
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
I want to declare global variables and Initialize objects like a global keyvalue store, some maps needed for my app flow etc.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
B4XMainPage is a good place for such variables. There are other good places as well.
Hello Erel!
Thank you for your response!
If I need to use FusedLocationProvider and I don't use the starter service, how it's better to implement it? Inside another service, in a class or just into MainPage? Note that only MainPage needs to use it in my case!
 
Upvote 0

Guenter Becker

Active Member
Licensed User

I also used the starter class before I turned over to B4XPages. In my fist steps with this I used starter as well until I read erels comments doing so. This forces me to think about a central point in the app code where to put starter/app globals and I decided to do it in the globals section of a modul (modul1) declaring them as public globals. It works very well only different thing is to put the moduls name before the globals name like modul1.globalname.

Yet I am playing around where to put the starters background services and at the moment I think I ll do it also in the modul or in the mainpage. If you have an comment or proposal to solve this please let me now.

Keep well Guenter
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I also used the starter class before I turned over to B4XPages.

@Guenter Becker ... Just for clarification is your project Cross Platform ?

The way I Interpret / understand it .. even if you are using B4XPages in an Non cross platform app (B4A only) it would still be recommended / wise
to use the Starter Service for declaring global objects , background tasks etc. ... as it was before B4XPages.
 
Last edited:
Upvote 0

Guenter Becker

Active Member
Licensed User
Thank you that is good to now because my projects are all focused on B4A. Following your statement means for me back to the roots and transfering the code back to the starter.

Keep well Guenter
 
Upvote 0

Guenter Becker

Active Member
Licensed User
OK helps me thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…