Android Question Tips to update the content of the B4XPage 3 times at day

asales

Expert
Licensed User
Longtime User
I move a activity project to a b4xpages project.
The app shows differents informations in each time of day (morning, afternoon, night).

Due this new behavior "The UI state is kept as long as the process lives" when I reopen the app in afternoon the information remains the same of the morning.

We have the B4XPage_Foreground and B4XPage_Appear events to treat this situation, but I don't want to update the UI every time that the app opens (only when the information changes).

I would like to know how you update your information in the app using b4xpages. There are a best way?

Thanks in advance for any tips.
 

josejad

Expert
Licensed User
Longtime User
What about not update the UI in B4XPage_Appear, but just check the hour and update the UI if it's time to do it?
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
you will need to use B4XPage_Appear, note that every time the application is finished, B4XPage_Created first starts and then B4XPage_Appear is called.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private imgImagem As B4XImageView
    Private lblFrase As B4XView
    Private pnlFundo As B4XView
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Log(DateTime.Time(DateTime.now) & "B4XPage_Created")
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Sub B4XPage_Appear
    Log(DateTime.Time(DateTime.now) & "B4XPage_Appear")
    carregarInformacoes
End Sub

Sub carregarInformacoes
    Dim horas As Int = DateTime.GetHour(DateTime.Now)
    Select horas
        Case 6, 7, 8, 9, 10, 11
            lblFrase.Text = "Bom dia"
            imgImagem.Load(File.DirAssets, "dia.jpg")
        Case 12, 13, 14, 15, 16, 17, 18
            lblFrase.Text = "Boa tarde"
            imgImagem.Load(File.DirAssets, "tarde.jpg")
        Case Else
            lblFrase.Text = "Boa noite"
            imgImagem.Load(File.DirAssets, "noite.jpg")
    End Select
End Sub

View attachment 151734View attachment 151735View attachment 151736
 

Attachments

  • Project.zip
    53.7 KB · Views: 81
Upvote 0
Top