Redone in B4A - Take into account Erel's comments about timers though
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim tmrCountdown As Timer
Dim tmrSeconds As Int
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private Button1 As B4XView
Private Label1 As B4XView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
tmrCountdown.Initialize("tmr",1000)
tmrCountdown.Enabled=False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
tmrSeconds=30
tmrCountdown.Enabled = True
End Sub
Sub tmr_tick
tmrSeconds=tmrSeconds-1
Label1.Text= tmrSeconds
If tmrSeconds=0 Then tmrCountdown.Enabled=False
End Sub
After execution, the code leaves the page
java.lang.IllegalStateException: Interval must be larger than 0.
at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:79)
at b4a.example.rgeg._activity_create(rgeg.java:482)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at b4a.example.rgeg.afterFirstLayout(rgeg.java:104)
at b4a.example.rgeg.access$000(rgeg.java:17)
at b4a.example.rgeg$WaitForLayout.run(rgeg.java:82)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7561)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)