Android Question Date and time

DonManfred

Expert
Licensed User
it does work without a timer too
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public clockrunning, shouldRun As Boolean
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private lblClock As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    lblClock.text = $"$date{DateTime.Now}: $time{DateTime.Now}"$
    clockrunning = False
End Sub
Sub Startclock
    Do While shouldRun
        clockrunning = True
        lblClock.text = $"$date{DateTime.Now}: $time{DateTime.Now}"$
        Sleep(1000)
    Loop
End Sub
Sub Activity_Resume
    shouldRun = True
    If clockrunning = False Then
        Startclock
    End If
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    shouldRun = False
    clockrunning = False
End Sub
 

Attachments

Geezer

Active Member
Licensed User
I never would have thought of doing it that way. Been a while since I wrote anything new and haven't really experimented with sleep too much.
 
Top