Android Question one shot timer

MbedAndroid

Active Member
Licensed User
b4a has a periodic timer, you can enable and disable it.
You cannot read the current value the moment you disabled it neither you can write a new value, or just only by initing the timer

I get the idea that when you start/stop/start the timer, it will continue at the last count, so no reset to initial value.
The only way seems to be to reinit the timer every time it seems, but may be i'm wrong?

I need that one shot timer to set a timeout when receiving data.
 

JordiCP

Well-Known Member
Licensed User
Don't know if it is what you are after, but if you need a one-shot timer, you only have to do disable it in its Tick event vand set it again when you need it

B4X:
Sub myTimer_Tick
  myTimer.Enabled=False 'one shot
  'and perform any action or set some flag...
  flg_timeOut=True 'for instance
end sub
and set it again when you want
B4X:
Sub Set_Timer
  flag_TimeOut=False
  myTimer.interval=1000 'whatever
  myTimer.enabled=True
end sub
 

RandomCoder

Well-Known Member
Licensed User
B4X:
Sub Set_Timer
  flag_TimeOut=False
  myTimer.interval=1000 'whatever
  myTimer.enabled=True
end sub
@MbedAndroid I use a slight variation on this in that I can also change the interval time with my sub call...
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