Android Question change a timer interval

Devv

Active Member
Licensed User
How could i change a timer interval ?

is initializing a timer more than once safe ?
 

Devv

Active Member
Licensed User
i had already red it ..
it does not talk about changing timer interval , it only say about initializing the timer for the first time
 

Devv

Active Member
Licensed User
Well, read it again, it says right there:
B4X:
Interval As Long
Gets or sets the interval between tick events, measured in milliseconds.
so at the second time i dont have to use this

Initialize (EventName As String, Interval As Long)

i should only use
timer1.interval = 2000


am i right ?
 

Devv

Active Member
Licensed User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    test.Initialize("test",2000)
    test.Enabled = True
End Sub

Sub test_tick
    ToastMessageShow("test",False)
    test.Interval = 6000
End Sub
ya this code is working perfectly , thanks for help dude , you are noobs hero :D
 

RandomCoder

Well-Known Member
Licensed User
Yes you're right, you don't need to initialise it again. I normally call a sub to stop the timer, set the new interval and then restart the timer to ensure that the first tick event is from time 0 to the interval time eg.
B4X:
..... ' your other code
    tmr_Reset(2500) ' reset timer to 2.5s interval
....


Sub tmr_Reset(ms As Int)
    tmr.Enabled=False
    tmr.Interval=ms
    tmr.Enabled=True
End Sub
 
Top