Android Question Better Localisator access if defined in Main?

Cadenzo

Active Member
Licensed User
Longtime User
Just one question: The localization example in B4XPages Project-zip sample has only one page. But if I have more pages and want to call the loc object (Localisator class) in B4XMainPage from another page, I have to use" CallSubDelayed" or B4XPages.GetPage("...").

I think it would be better to declare class and define "loc" object in the Main-Module in Activity_Create. Than it is accessible from everywhere just with Main.loc(...). Is that a good way to do?
 

aeric

Expert
Licensed User
Longtime User
Just one question: The localization example in B4XPages Project-zip sample has only one page. But if I have more pages and want to call the loc object (Localisator class) in B4XMainPage from another page, I have to use" CallSubDelayed" or B4XPages.GetPage("...").

I think it would be better to declare class and define "loc" object in the Main-Module in Activity_Create. Than it is accessible from everywhere just with Main.loc(...). Is that a good way to do?
Yes, I guess you didn't read the whole thread and missed my example.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Thanks aeric, your example is, how I plant it to do. And still I am thinking, where is the best location to initialize loc (in Activity_Create?), as in B4A/B4i I have no Sub AppStart.

Main module::
Sub Activity_Create(FirstTime As Boolean)
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
    If FirstTime Then
        Loc.Initialize(File.DirAssets, "strings.db")
    End If
End Sub
Hope, that here is everything okay.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Thanks aeric, your example is, how I plant it to do. And still I am thinking, where is the best location to initialize loc (in Activity_Create?), as in B4A/B4i I have no Sub AppStart.

Main module::
Sub Activity_Create(FirstTime As Boolean)
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
    If FirstTime Then
        Loc.Initialize(File.DirAssets, "strings.db")
    End If
End Sub
Hope, that here is everything okay.
You can also do it in B4XPage_Created
edit: I have updated my example.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Main.Loc.Initialize(File.DirAssets, "strings.db")
    LocalizePage ' apply Localization
   
    B4XPage2.Initialize
    B4XPages.AddPage("Page2", B4XPage2)
End Sub
 
Last edited:
Upvote 0
Top