Android Question [Resolved] Trouble getting timer to work

DataMiser

Member
Licensed User
Hi Guys, been a while since I worked with B4A, just getting back to it to do a simple project and ran into an issue with a Timer that has me scratching my head.
Here is the relevant code
B4X:
Sub Process_Globals
    Dim Timer1 As Timer
End Sub
Sub Globals
   Private Label1 As Label
   Private Panel1 As Panel
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("scrMenu")
     If FirstTime=True Then
         Timer1.Initialize(Timer1_Tick, 250)
         Timer1.Enabled=False
     End If
     Timer1.Enabled=True
End Sub

Sub Timer1_Tick
     Panel1.Color= Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)) 
End Sub

When I test the code above the timer sub fires once and sets the color to some random color but then it does not continue to fire afterwards.

What am I missing here?
 

eurojam

Well-Known Member
Licensed User
Longtime User
it should be
B4X:
Sub Process_Globals
    Dim Timer1 As Timer
End Sub
Sub Globals
   Private Label1 As Label
   Private Panel1 As Panel
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("scrMenu")
     'If FirstTime=True Then
         Timer1.Initialize("Timer1", 250)
     '    Timer1.Enabled=False
     'End If  do you realy need that?
     Timer1.Enabled=True
End Sub

Sub Timer1_Tick
     Panel1.Color= Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
End Sub

you see the difference? Timer1 is the EventName and Timer1_Tick the event
 
Upvote 0
Top