Android Question change a timer interval

Devv

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

is initializing a timer more than once safe ?
 

Devv

Active Member
Licensed User
Longtime 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
 
Upvote 0

Devv

Active Member
Licensed User
Longtime 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 ?
 
Upvote 0

Devv

Active Member
Licensed User
Longtime 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
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0
Top