Android Question B4XPages Initialize

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello,

I initialize my app as code shown below. Everything works fine but i am curious if it's the correct way.

B4X:
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
    B4XPages.GetManager.TransitionAnimationDuration = 0
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)

    Root = Root1
 
    registerPage.Initialize
    B4XPages.AddPage("registerPage",registerPage)
 
    restorePasswordPage.Initialize
    B4XPages.AddPage("restorePasswordPage",restorePasswordPage)
 
    loginPage.Initialize
    B4XPages.AddPage("login",loginPage)
 
    likesPage.Initialize
    B4XPages.AddPage("likesPage", likesPage)
 
    fullProfilePage.Initialize
    B4XPages.AddPage("fullProfilePage", fullProfilePage)
 
    viewLogPage.Initialize
    B4XPages.AddPage("viewLogPage", viewLogPage)
 
    prsPage.Initialize
    B4XPages.AddPage("prsPage", prsPage)
 
    friendsPage.Initialize
    B4XPages.AddPage("friendsPage", friendsPage)
 
    benchmarksPage.Initialize
    B4XPages.AddPage("benchmarksPage", benchmarksPage)
 
    calculatorPage.Initialize
    B4XPages.AddPage("calculatorPage", calculatorPage)
 
    checkinPage.Initialize
    B4XPages.AddPage("checkinPage", checkinPage)
 
    settingsPage.Initialize
    B4XPages.AddPage("settingsPage", settingsPage)
 
    updatePasswordPage.Initialize
    B4XPages.AddPage("updatePasswordPage", updatePasswordPage)
 
    newPasswordPage.Initialize
    B4XPages.AddPage("newPasswordPage",newPasswordPage)
 
    chatPage.Initialize
    B4XPages.AddPage("chatPage",chatPage)
 
    userChatPage.Initialize
    B4XPages.AddPage("userChatPage",userChatPage)

    wsh.Initialize(Me, "wsh")
     
End Sub

Private Sub B4XPage_Appear
    If Root.NumberOfViews=0 Then
        If Starter.KVS.GetDefault("id_user","")<>"" Then
            If wsh.ws.Connected = False Then wsh.Connect(appointmentSocket)

            selectUserMe(Starter.KVS.Get("id_user")) 'Getting user data and loading main layout and loading other staff
        Else
            B4XPages.ShowPageAndRemovePreviousPages("login") 'If no user is logged in, then remove b4xmain and show login page
        End If
    Else
        If wsh.ws.Connected = False Then wsh.Connect(appointmentSocket)
    End If
End Sub

Thank you.
 
Last edited:

yiankos1

Well-Known Member
Licensed User
Longtime User
So, if it is the correct way loading b4xpages i have this problem with notifications:

1) I open my app and click back button in order to exit app
2) I clear apps from memory
3) When i send a notification, log stops there:
B4X:
*** Receiver (firebasemessaging) Receive (first time) ***
Message arrived
Message data: {chatMessageID=d2dac0b7-263b-af8a-837c-4392e617fc75, chatID=132c703f-6f34-11ee-a7a2-52894e2c9ee7, typeNotification=chat, userTo=169097122283136, userSent=2dcc00c6-4da4-11ee-a7fa-52894e2c9ee7, body=S, title=ΕΠΩΝΥΜΟ ΟΝΟΜΑ}
** Service (starter) Start **
App is shown to be loaded but nothing loaded, just a black screen. Nothing from B4XPages loaded. I initialize nothing on starter service.
Resume sub:
B4X:
Sub Activity_Resume
    B4XPages.Delegate.Activity_Resume
  
    Dim in As Intent
    in = Activity.GetStartingIntent
    If in.HasExtra("Notification_Tag") Then
        Log(in.GetExtra("Notification_Tag")) 'Will log the tag
      
        Dim jp As JSONParser
        jp.Initialize(in.GetExtra("Notification_Tag"))
        Dim root As Map = jp.NextObject
        Dim typeNotification As String = root.Get("typeNotification")
      
        Select typeNotification
            Case "changeSubNember"
                B4XPages.MainPage.tabMenu_TabClick(1)
            Case "chat"
                Dim userSent As String = root.Get("userSent")
              
                B4XPages.ShowPage("chatPage")
              
                B4XPages.MainPage.chatPage.getChat(userSent)
        End Select
  
    End If
End Sub

I can reproduce this behavior on Pixel 7 Pro (SDK 34). On an older smartphone, everything works fine.
 
Last edited:
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
You should ask the question in a new thread.

I didn't delve into it; I just see that you write code in a place where I wouldn't do it, it should be written in the B4XPages, the B4XMainPage in your case.
Thanks Lucas. I will create a new thread.

Activity_Resume code i attached, is the notification intent handler. It just redirects you to the correct b4xpage according to notification tag.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…