Android Question Timer not ticking

wwregistry

Member
Licensed User
Longtime User
here is my code
the ******...indicate the initial path that doesn't activate ticks

MAIN

Sub Process_Globals

Dim Frequency1 As Int
Dim Frequency2 As Int
Dim Abort As Boolean
Dim CountLengthInSeconds As Int
Dim PauseLengthInSeconds As Int
Dim countUpDown As Int
Dim SaveList As List
Dim BeepDuratrion As Long
Dim ContinuousRepeat As Boolean

Dim TotalSeconds As Long

End Sub

Sub Activity_Create(FirstTime As Boolean)

Frequency1 = 399
Frequency2 = 399
Abort = False
BeepDuratrion = 1000 'sec
SaveList.Initialize

StartActivity("SubActivity") '******************************************************
.
.
.

SUB ACTIVITY '************************************************
Sub Process_Globals

Dim MyTimer As Timer

End Sub

Sub Globals

Dim DisplayCounter As Label

Dim red As ImageView
Dim Green As ImageView
Dim Yellow As ImageView

Dim CountNum As EditText
Dim PauseNum As EditText
Dim Repeat As Label

Dim Panel1 As Panel

Dim Plus As ImageView
Dim PanelPlus As Panel
Dim Minus As ImageView
Dim PanelMinus As Panel

Dim MyBeeper As Beeper 'Need audio library

Dim i As Long
Dim t As Long
Dim t1 As Long

Dim TimerOn As Boolean

End Sub


Sub TimerStart '**************************************************

i = 0

MyTimer.Initialize("MyTimer", 1000)
t1=DateTime.Now

MyTimer.Enabled = True

End Sub

Sub MyTimer_Tick '*********************************************************
Dim t2 As Long

t2=DateTime.Now

If Main.Abort Then
MyPause
Else


i = i + 1

If Main.countUpDown = 1 Then
DisplayCounter.Text = 0 + i
Else
DisplayCounter.Text = t - i
End If

'MyBeeper.Beep

If t2-t1 >= t * 1000 Then
MyTimer.Enabled = False
MyBeeper.beep
TimerOn = False
End If
End If

End Sub

Sub MyPause

MyTimer.Enabled = False
MyBeeper.Release
Activity.Finish

End Sub


Sub Activity_KeyPress (KeyCode As Int) As Boolean

If KeyCode = KeyCodes.KEYCODE_BACK Then ' Checks if the KeyCode is BackKey
MyPause
End If

End Sub



Sub Activity_Create(FirstTime As Boolean)

'Load main layout file.
Activity.LoadLayout("Main")

If FirstTime Then
LoadTheStuff
End If

MyBeeper.Initialize(200, Main.Frequency1) '200 milliseconds, 500 hz
Start

End Sub

Sub Start '**********************************

Setup
GreenStart

End Sub

Sub GreenStart '**************************************

Do While (Main.ContinuousRepeat)
GreenGoOnce
Loop

Repeat.Enabled = True

Panel1.Enabled = True
Panel1.Visible = True

DisplayCounter.Text = "Start"

Green.Enabled = True
Green.Visible = True

red.Enabled = False
red.Visible = False

Yellow.Enabled = False
Yellow.Visible = False

End Sub


Sub Green_click '***********************clicking here to start timer sequence

Repeat.Enabled = False 'Visible but not active

Panel1.Visible = False
Panel1.Enabled = False

Green.Enabled = False
Green.Visible = False

red.Enabled = True
Yellow.Enabled = True

Main.Abort = False

GreenGoOnce
GreenStart

End Sub

Sub GreenGoOnce '****************************closer to starting time
If Main.CountLengthInSeconds > 0 Then
'MyBeeper(Main.BeepDuratrion, Main.Frequency1)
MyBeeper.Beep

RedRun '************************************getting read to start time
'*********************no ticks - like it ignored timer
If Main.Abort Then
Else
If Main.PauseLengthInSeconds > 0 Then
'Beep(Main.BeepDuratrion, Main.Frequency1)

YellowRun
Do While MyTimer.Enabled
Loop
If Main.Abort Then
Else
'MyBeeper(Main.BeepDuratrion, Main.Frequency2)
MyBeeper.Beep
End If
Else
'MyBeeper(Main.BeepDuratrion, Main.Frequency2)
MyBeeper.Beep
End If
End If
End If

End Sub

Sub Red_click

Main.Abort = True
Main.ContinuousRepeat = False
Repeat.Text = "Repeat OFF"

End Sub
Sub RedRun '********************************closer

DisplayCounter.Text = "Start"

red.Visible = True
Yellow.Visible = False

' Main.TotalSeconds = Main.CountLengthInSeconds
' StartActivity("RedTimer")
'****************************************here is where timer is called
t = Main.CountLengthInSeconds
TimerOn = True
TimerStart

End Sub
 

stevel05

Expert
Licensed User
Longtime User
It helps to use the code tags (5th icon from the right) to display code, it's easier to read. And for larger amounts, you will get a quicker response if you upload the project as a zip file (File/Export As zip in the IDE) so we don't have to recreate the project to test it.
 
Upvote 0

wwregistry

Member
Licensed User
Longtime User
Uploaded Project

current behavior: it shows a green dot, press click on the green dot and then it counts down from 5, 4,,3.... back to green - this is crazy behavior, not how it is programmed to behave - it appears that the timer is messing the flow up.

It is supposed to show the green down, press click, it turns to red (Start) to count down counts down, then turns yellow(Pause) and counts down then returns to green. If REPEAT is turned on, it supposed to go forever. However if the dots are clicked during the countdown it restarts at green.

I had to remove the object folder otherwise zip was too big.
 

Attachments

  • Timer.zip
    38.5 KB · Views: 256
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you tried setting a debug point and stepping through the code? Put a debug point at line 161, (click in the very left grey area of the IDE next to the line), then make sure debug is on. run the app, Click the green button in your app and when the program pauses click the green arrow pause sign in the IDE. It will step through each line of code. Each state is passed through, but there is nothing to hold it there while the timer ticks down so it appears to go straight back to green.

I don't know the design behind the code, but it seems to me that you should be using the timer tick sub to drive the calls to different states.
 
Last edited:
Upvote 0

wwregistry

Member
Licensed User
Longtime User
Thank u, Steve

I am familiar with the debugger. I see now that I have been staring at the problem for days -- "but there is nothing to hold it there while the timer ticks down" --- I had put a while timer.enabled loop in there to hold it -- but now I realize that a DOEVENTS statement in the loop and in the timer were necessary. Now it works great -- Thank u.. David Gray
 
Upvote 0
Top