Wish New Timer property and methods

LucaMs

Expert
Licensed User
Longtime User
a) How is it different than Timer1.Enabled?
Timer1.Enabled "starts" or "stops" the timer's "activity" (can I say "its countdown"?). Timer1.IsEnabled should be used to check if it was enabled (started).

b) You can disable the timer to pause it and then enable it to resume it.
I can (will) try but if you disable and then re-enable the timer, it will start from 0 (please, let me write in Italian :p).

I mean: if I wanted to suspend the timer?

I set Timer1.Interval to 1 minute; then I need to do something when the minute is not passed (or simply the user presses Home). I have to create a process global variable which stores the time passed and on activity resume I have to set the new Timer1's interval to the difference, the remaining time. Also, I have to reset again the Interval to 1 minute.

With Timer1.Pause - Timer1.Resume:
B4X:
Sub Activity_Pause(...)
    If not(UserClosed) then
          Timer1.Pause
...


Sub Activity_Resume
    ' Here I could have the need of: If Timer1.IsEnabled Then
    Timer1.Resume
...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Timer.Enabled is a get / set property. You can get its value:
B4X:
Dim IsEnabled As Boolean = Timer1.Enabled
I set Timer1.Interval to 1 minute; then I need to do something when the minute is not passed (or simply the user presses Home)
You should use a service in that case. The timers will not be affected by the application life cycle.
 

LucaMs

Expert
Licensed User
Longtime User
Timer.Enabled is a get / set property. You can get its value:
B4X:
Dim IsEnabled As Boolean = Timer1.Enabled

You should use a service in that case. The timers will not be affected by the application life cycle.

Timer.Enabled seem to be both, a property but also a method; you use it to start the "timer's countdown".
Anyway, your hint (to check if it is "active") is right (of course :)) .


About services... I have to study if I can help "him" using them. Sure not today, today my brain needs: "LucaMs.Pause" :p


What about that "stopwatch" object? Is it not useful?



Thank you, Erel
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
You should use a service in that case. The timers will not be affected by the application life cycle.

Do you mean he (we) should use services with StartServiceAt instead of timers? But he uses many timers to show-hide-change images and to do other stuff and services have no GUI and are not related to Activities. I suppose he should pass GUI objects to them, but it is very complex, or not?
 
Last edited:
Top